'\d+'], normalizationContext: ['groups' => ['shipment:read']], ), new GetCollection( normalizationContext: ['groups' => ['shipment:read']], ), new Post( normalizationContext: ['groups' => ['shipment:read']], denormalizationContext: ['groups' => ['shipment:write']], ), new Patch( requirements: ['id' => '\d+'], normalizationContext: ['groups' => ['shipment:read']], denormalizationContext: ['groups' => ['shipment:write']], ), new Get( uriTemplate: '/shipments/weigh', openapi: new OpenApiOperation( summary: 'Fetch the current weight reading', description: 'Queries the pont-bascule and returns the weight data.', ), normalizationContext: ['groups' => ['shipment:weigh:read']], output: PontBasculeReading::class, provider: ShipmentWeighingProvider::class, ), new Get( uriTemplate: '/shipments/{id}/receipt', requirements: ['id' => '\d+'], openapi: new OpenApiOperation( summary: 'Render a shipment receipt', description: 'Returns a PDF receipt for the shipment.', ), output: false, provider: ShipmentReceiptProvider::class, ), ], security: "is_granted('ROLE_USER')", )] class Shipment { #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] #[Groups(['shipment:read'])] private ?int $id = null; #[ORM\Column(length: 255)] #[Groups(['shipment:read', 'shipment:write'])] private ?string $licencePlate = null; #[ORM\Column(length: 20, unique: true, nullable: true)] #[Groups(['shipment:read'])] private ?string $identificationNumber = null; #[ORM\Column(options: ['default' => 0])] #[Groups(['shipment:read', 'shipment:write'])] private int $currentStep = 0; #[ORM\Column] #[Groups(['shipment:read', 'shipment:write'])] private bool $isValid = false; #[ORM\ManyToOne] #[ORM\JoinColumn(nullable: true)] #[Groups(['shipment:read', 'shipment:write'])] #[ApiProperty(readableLink: true)] private ?User $user = null; #[ORM\Column(name: 'shipment_date', type: 'datetime_immutable')] #[Groups(['shipment:read', 'shipment:write'])] #[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])] private ?DateTimeImmutable $shipmentDate = null; #[ORM\ManyToOne] #[ORM\JoinColumn(nullable: true)] #[Groups(['shipment:read', 'shipment:write'])] #[ApiProperty(readableLink: true)] private ?Carrier $carrier = null; #[ORM\ManyToOne] #[ORM\JoinColumn(nullable: true)] #[Groups(['shipment:read', 'shipment:write'])] #[ApiProperty(readableLink: true)] private ?Truck $truck = null; #[ORM\ManyToOne] #[ORM\JoinColumn(nullable: true)] #[Groups(['shipment:read', 'shipment:write'])] #[ApiProperty(readableLink: true)] private ?Customer $customer = null; #[ORM\ManyToOne(inversedBy: 'shipments')] #[ORM\JoinColumn(nullable: true)] #[Groups(['shipment:read', 'shipment:write'])] #[ApiProperty(readableLink: true)] private ?ShipmentType $shipmentType = null; #[ORM\Column] #[Groups(['shipment:read', 'shipment:write'])] private int $nbBovinSend = 0; /** * @var Collection */ #[ORM\OneToMany(targetEntity: Weight::class, mappedBy: 'shipment', cascade: ['persist', 'remove'], orphanRemoval: true)] #[Groups(['shipment:read'])] private Collection $weights; #[ORM\ManyToOne] #[ORM\JoinColumn(nullable: true)] #[Groups(['shipment:read', 'shipment:write'])] #[ApiProperty(readableLink: true)] private ?Driver $driver = null; #[ORM\ManyToOne] #[ORM\JoinColumn(nullable: true)] #[Groups(['shipment:read', 'shipment:write'])] #[ApiProperty(readableLink: true)] private ?Address $address = null; public function __construct() { $this->weights = new ArrayCollection(); } public function getId(): ?int { return $this->id; } public function getLicencePlate(): ?string { return $this->licencePlate; } public function setLicencePlate(?string $licencePlate): void { $this->licencePlate = $licencePlate; } public function getIdentificationNumber(): ?string { return $this->identificationNumber; } public function setIdentificationNumber(?string $identificationNumber): void { $this->identificationNumber = $identificationNumber; } public function getCurrentStep(): int { return $this->currentStep; } public function setCurrentStep(int $currentStep): void { $this->currentStep = $currentStep; } public function getShipmentType(): ?ShipmentType { return $this->shipmentType; } public function setShipmentType(?ShipmentType $shipmentType): void { $this->shipmentType = $shipmentType; } public function getNbBovinSend(): int { return $this->nbBovinSend; } public function setNbBovinSend(int $nbBovinSend): void { $this->nbBovinSend = $nbBovinSend; } public function getIsValid(): ?bool { return $this->isValid; } #[Groups(['shipment:read'])] public function isValid(): bool { return $this->isValid; } public function getUser(): ?User { return $this->user; } public function setUser(?User $user): void { $this->user = $user; } public function setIsValid(?bool $isValid): void { $this->isValid = $isValid; } public function getShipmentDate(): ?DateTimeImmutable { return $this->shipmentDate; } public function setShipmentDate(?DateTimeImmutable $shipmentDate): void { $this->shipmentDate = $shipmentDate; } public function getCarrier(): ?Carrier { return $this->carrier; } public function setCarrier(?Carrier $carrier): void { $this->carrier = $carrier; } public function getTruck(): ?Truck { return $this->truck; } public function setTruck(?Truck $truck): void { $this->truck = $truck; } public function getCustomer(): ?Customer { return $this->customer; } public function setCustomer(?Customer $customer): void { $this->customer = $customer; } /** * @return Collection */ public function getWeights(): Collection { return $this->weights; } public function addWeight(Weight $weight): void { if (!$this->weights->contains($weight)) { $this->weights->add($weight); $weight->setShipment($this); } } public function removeWeight(Weight $weight): void { if ($this->weights->removeElement($weight)) { if ($weight->getShipment() === $this) { $weight->setShipment(null); } } } #[ORM\PostPersist] public function initializeIdentificationNumber(PostPersistEventArgs $args): void { if (null !== $this->identificationNumber) { return; } if (null === $this->id) { return; } $number = sprintf('P-BL-%04d', $this->id); $this->identificationNumber = $number; $args->getObjectManager() ->getConnection() ->executeStatement( 'UPDATE shipment SET identification_number = :number WHERE id = :id', [ 'number' => $number, 'id' => $this->id, ] ) ; } public function getDriver(): ?Driver { return $this->driver; } public function setDriver(?Driver $driver): static { $this->driver = $driver; return $this; } public function getAddress(): ?Address { return $this->address; } public function setAddress(?Address $address): static { $this->address = $address; return $this; } }