Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | #271 | Créer une nouvelle expédition (étape 1) | ## 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: kevin <kevin@yuno.malio.fr> Reviewed-on: #12 Reviewed-by: Autin <tristan@yuno.malio.fr> Co-authored-by: Matteo <matteo@yuno.malio.fr> Co-committed-by: Matteo <matteo@yuno.malio.fr>
167 lines
4.4 KiB
PHP
167 lines
4.4 KiB
PHP
<?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 DateTimeImmutable;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
|
use Symfony\Component\Serializer\Attribute\Context;
|
|
use Symfony\Component\Serializer\Attribute\Groups;
|
|
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
#[ORM\Entity]
|
|
#[ORM\Table(name: 'weight')]
|
|
#[ApiResource(
|
|
operations: [
|
|
new Get(normalizationContext: ['groups' => ['weight:read']]),
|
|
new GetCollection(normalizationContext: ['groups' => ['weight:read']]),
|
|
new Post(
|
|
normalizationContext: ['groups' => ['weight:read']],
|
|
denormalizationContext: ['groups' => ['weight:write']],
|
|
),
|
|
new Patch(
|
|
normalizationContext: ['groups' => ['weight:read']],
|
|
denormalizationContext: ['groups' => ['weight:write']],
|
|
),
|
|
],
|
|
security: "is_granted('ROLE_USER')",
|
|
)]
|
|
#[UniqueEntity(fields: ['reception', 'type'], message: 'A weighing already exists for this type.')]
|
|
#[UniqueEntity(fields: ['shipment', 'type'], message: 'A weighing already exists for this type.')]
|
|
#[Assert\Expression(
|
|
'(this.getReception() !== null and this.getShipment() === null) or (this.getReception() === null and this.getShipment() !== null)',
|
|
message: 'Either reception or shipment must be set, but not both.'
|
|
)]
|
|
class Weight
|
|
{
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column]
|
|
#[Groups(['reception:read', 'shipment:read', 'weight:read'])]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\ManyToOne(inversedBy: 'weights')]
|
|
#[ORM\JoinColumn(nullable: true)]
|
|
#[Groups(['weight:read', 'weight:write'])]
|
|
private ?Reception $reception = null;
|
|
|
|
#[ORM\ManyToOne(inversedBy: 'weights')]
|
|
#[ORM\JoinColumn(nullable: true)]
|
|
#[Groups(['weight:read', 'weight:write'])]
|
|
private ?Shipment $shipment = null;
|
|
|
|
#[ORM\Column(nullable: true)]
|
|
#[Groups(['reception:read', 'shipment:read', 'weight:read', 'weight:write'])]
|
|
#[Assert\PositiveOrZero]
|
|
private ?int $dsd = null;
|
|
|
|
#[ORM\Column(nullable: true)]
|
|
#[Groups(['reception:read', 'shipment:read', 'weight:read', 'weight:write'])]
|
|
#[Assert\PositiveOrZero]
|
|
private ?int $weight = null;
|
|
|
|
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
|
|
#[Groups(['reception:read', 'shipment:read', 'weight:read', 'weight:write'])]
|
|
#[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
|
|
private ?DateTimeImmutable $weighedAt = null;
|
|
|
|
#[ORM\Column(length: 10)]
|
|
#[Groups(['reception:read', 'shipment:read', 'weight:read', 'weight:write'])]
|
|
#[Assert\NotBlank]
|
|
#[Assert\Choice(choices: ['gross', 'tare'])]
|
|
private string $type = 'gross';
|
|
|
|
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->getWeights()->contains($this)) {
|
|
$reception->addWeight($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getShipment(): ?Shipment
|
|
{
|
|
return $this->shipment;
|
|
}
|
|
|
|
public function setShipment(?Shipment $shipment): self
|
|
{
|
|
$this->shipment = $shipment;
|
|
|
|
if (null !== $shipment && !$shipment->getWeights()->contains($this)) {
|
|
$shipment->addWeight($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getDsd(): ?int
|
|
{
|
|
return $this->dsd;
|
|
}
|
|
|
|
public function setDsd(?int $dsd): self
|
|
{
|
|
$this->dsd = $dsd;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getWeight(): ?int
|
|
{
|
|
return $this->weight;
|
|
}
|
|
|
|
public function setWeight(?int $weight): self
|
|
{
|
|
$this->weight = $weight;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getWeighedAt(): ?DateTimeImmutable
|
|
{
|
|
return $this->weighedAt;
|
|
}
|
|
|
|
public function setWeighedAt(?DateTimeImmutable $weighedAt): self
|
|
{
|
|
$this->weighedAt = $weighedAt;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getType(): string
|
|
{
|
|
return $this->type;
|
|
}
|
|
|
|
public function setType(string $type): self
|
|
{
|
|
$this->type = $type;
|
|
|
|
return $this;
|
|
}
|
|
}
|