src/Entity/Expediting/Package.php line 65
<?php
namespace App\Entity\Expediting;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Link;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use App\Doctrine\Type\Expediting\CasingMaterial;
use App\Doctrine\Type\Expediting\CasingType;
use App\Doctrine\Type\Expediting\ExpeditableStatus;
use App\Dto\Expediting\PackageSurveyInput;
use App\Entity\Common as Common;
use App\Entity\File\File;
use App\Entity\Inventory\PackageMovement;
use App\Processor\Expediting\PackageSurveyInputProcessor;
use App\Validator\IsValidEnum\IsValidEnum;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Ignore;
use Symfony\Component\Uid\Ulid;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Table(name: 'expediting_package')]
#[ORM\Index(columns: ['destination_repacking_id'], name: 'expediting_package_destination_repacking_id_idx')]
#[ORM\Index(columns: ['source_repacking_id'], name: 'expediting_package_source_repacking_id_idx')]
#[ORM\Index(columns: ['created_by'], name: 'expediting_package_created_by_idx')]
#[ORM\Index(columns: ['updated_by'], name: 'expediting_package_updated_by_idx')]
#[ORM\UniqueConstraint(name: 'expediting_package_slug_key', columns: ['slug'])]
#[ORM\UniqueConstraint(name: 'expediting_package_reference_key', columns: ['reference'])]
#[ORM\UniqueConstraint(name: 'expediting_package_identifier_key', columns: ['identifier'])]
#[ORM\Entity]
#[UniqueEntity(fields: ['reference'])]
#[ApiResource(
operations: [
new Get(),
new GetCollection(),
new Post(),
new Put(),
new Patch(),
new Delete(),
new Post(
uriTemplate: '/packages/survey',
inputFormats: ['json' => ['application/json'], 'multipart' => ['multipart/form-data']],
input: PackageSurveyInput::class,
processor: PackageSurveyInputProcessor::class
),
],
routePrefix: '/expediting'
)]
#[ApiResource(
uriTemplate: '/expediting/shipments/{slug}/packages',
operations: [new GetCollection()],
uriVariables: ['slug' => new Link(fromProperty: 'packages', fromClass: Shipment::class)],
)]
class Package
{
use Common\Blameable;
use Common\Trackable;
use Shippable;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
#[ORM\SequenceGenerator(sequenceName: 'expediting_package_id_seq')]
#[ORM\Column(type: Types::INTEGER)]
#[ApiProperty(identifier: false)]
private ?int $id = null;
#[Assert\Ulid]
#[Assert\NotNull]
#[ORM\Column(type: 'ulid', unique: true)]
private ?Ulid $identifier = null;
#[Gedmo\Slug(fields: ['reference'])]
#[ORM\Column(type: Types::STRING)]
#[ApiProperty(identifier: true)]
private ?string $slug = null;
#[Assert\NotBlank]
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING)]
private ?string $reference = null;
#[Assert\NotBlank]
#[Assert\Type(type: Types::STRING)]
#[ORM\Column(type: Types::STRING)]
private ?string $packageNumber = null;
#[Assert\Type(type: Types::FLOAT)]
#[ORM\Column(type: Types::DECIMAL, precision: 18, scale: 3, nullable: true)]
private ?float $length = null;
#[Assert\Type(type: Types::FLOAT)]
#[ORM\Column(type: Types::DECIMAL, precision: 18, scale: 3, nullable: true)]
private ?float $width = null;
#[Assert\Type(type: Types::FLOAT)]
#[ORM\Column(type: Types::DECIMAL, precision: 18, scale: 3, nullable: true)]
private ?float $height = null;
#[Assert\Type(type: Types::FLOAT)]
#[ORM\Column(type: Types::DECIMAL, precision: 18, scale: 3, nullable: true)]
private ?float $weight = null;
#[Assert\Type(type: Types::FLOAT)]
#[ORM\Column(type: Types::DECIMAL, precision: 18, scale: 3, nullable: true)]
private ?float $shippingWeight = null;
#[Assert\NotNull]
#[Assert\Type(type: Types::BOOLEAN)]
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
private ?bool $openable = false;
#[Assert\NotNull]
#[Assert\Type(type: Types::BOOLEAN)]
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
private ?bool $destroyed = false;
#[IsValidEnum(enum: CasingType::class)]
#[ORM\Column(type: Types::STRING, nullable: true, enumType: CasingType::class)]
private ?CasingType $casingType = null;
#[IsValidEnum(enum: CasingMaterial::class)]
#[ORM\Column(type: Types::STRING, nullable: true, enumType: CasingMaterial::class)]
private ?CasingMaterial $casingMaterial = null;
#[Assert\NotNull]
#[IsValidEnum(enum: ExpeditableStatus::class)]
#[ORM\Column(type: Types::STRING, enumType: ExpeditableStatus::class)]
private ?ExpeditableStatus $status = null;
#[ORM\ManyToOne(targetEntity: Repacking::class, inversedBy: 'inputs')]
#[ORM\JoinColumn(name: 'destination_repacking_id')]
private ?Repacking $destinationRepacking = null;
#[ORM\ManyToOne(targetEntity: Repacking::class, inversedBy: 'outputs')]
#[ORM\JoinColumn(name: 'source_repacking_id')]
private ?Repacking $sourceRepacking = null;
/** @var Collection<int, Shipment> */
#[ORM\ManyToMany(targetEntity: Shipment::class, mappedBy: 'packages')]
private Collection $shipments;
/** @var Collection<int, Container> */
#[ORM\ManyToMany(targetEntity: Container::class, mappedBy: 'packages')]
private Collection $containers;
/** @var Collection<int, PackageMovement> */
#[ORM\OneToMany(mappedBy: 'package', targetEntity: PackageMovement::class)]
#[ORM\OrderBy(['id' => 'DESC'])]
#[Ignore]
private Collection $movements;
/** @var Collection<int, Expeditable> */
#[ORM\ManyToMany(targetEntity: Expeditable::class, inversedBy: 'packages')]
#[ORM\JoinTable(name: 'expediting_package_item_map')]
#[ORM\JoinColumn(name: 'package_id')]
#[ORM\InverseJoinColumn(name: 'item_id')]
private Collection $items;
/** @var Collection<int, File> */
#[ORM\ManyToMany(targetEntity: File::class, cascade: ['persist', 'remove'])]
#[ORM\JoinTable(name: 'expediting_package_file_map')]
#[ORM\JoinColumn(name: 'package_id')]
#[ORM\InverseJoinColumn(name: 'file_id')]
#[ORM\OrderBy(['id' => 'ASC'])]
private Collection $attachments;
public function __construct()
{
$this->identifier = new Ulid();
$this->shipments = new ArrayCollection();
$this->containers = new ArrayCollection();
$this->movements = new ArrayCollection();
$this->items = new ArrayCollection();
$this->attachments = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getIdentifier(): ?Ulid
{
return $this->identifier;
}
public function setIdentifier(Ulid $identifier): self
{
$this->identifier = $identifier;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getReference(): ?string
{
return $this->reference;
}
public function setReference(string $reference): self
{
$this->reference = $reference;
return $this;
}
public function getPackageNumber(): ?string
{
return $this->packageNumber;
}
public function setPackageNumber(string $packageNumber): self
{
$this->packageNumber = $packageNumber;
return $this;
}
public function getWidth(): ?string
{
return (string) $this->width;
}
public function setWidth(float|string|null $width): self
{
$this->width = null === $width ? null : (float) $width;
$this->setShippingWeight();
return $this;
}
public function getLength(): ?string
{
return (string) $this->length;
}
public function setLength(float|string|null $length): self
{
$this->length = null === $length ? null : (float) $length;
$this->setShippingWeight();
return $this;
}
public function getHeight(): ?string
{
return (string) $this->height;
}
public function setHeight(float|string|null $height): self
{
$this->height = null === $height ? null : (float) $height;
$this->setShippingWeight();
return $this;
}
public function getWeight(): ?string
{
return (string) $this->weight;
}
public function setWeight(float|string|null $weight): self
{
$this->weight = null === $weight ? null : (float) $weight;
return $this;
}
public function getShippingWeight(): ?string
{
return (string) $this->shippingWeight;
}
public function setShippingWeight(): self
{
$volume = ($this->width * $this->length * $this->height) / 6_000;
$shippingWeight = max($this->weight, $volume);
$this->shippingWeight = $shippingWeight;
return $this;
}
public function isOpenable(): ?bool
{
return $this->openable;
}
public function setOpenable(bool $openable): self
{
$this->openable = $openable;
return $this;
}
public function isDestroyed(): ?bool
{
return $this->destroyed;
}
public function setDestroyed(bool $destroyed): self
{
$this->destroyed = $destroyed;
return $this;
}
public function getCasingType(): ?CasingType
{
return $this->casingType;
}
public function setCasingType(?CasingType $casingType): self
{
$this->casingType = $casingType;
return $this;
}
public function getCasingMaterial(): ?CasingMaterial
{
return $this->casingMaterial;
}
public function setCasingMaterial(?CasingMaterial $casingMaterial): self
{
$this->casingMaterial = $casingMaterial;
return $this;
}
public function getStatus(): ?ExpeditableStatus
{
return $this->status;
}
public function setStatus(?ExpeditableStatus $status): self
{
$this->status = $status;
return $this;
}
/**
* @return Collection<int, Shipment>
*/
public function getShipments(): Collection
{
return $this->shipments;
}
public function addShipment(Shipment $shipment): self
{
if (!$this->shipments->contains($shipment)) {
$this->shipments->add($shipment);
$shipment->addPackage($this);
}
return $this;
}
public function removeShipment(Shipment $shipment): self
{
if ($this->shipments->removeElement($shipment)) {
$shipment->removePackage($this);
}
return $this;
}
/**
* @return Collection<int, Container>
*/
public function getContainers(): Collection
{
return $this->containers;
}
public function addContainer(Container $container): self
{
if (!$this->containers->contains($container)) {
$this->containers->add($container);
$container->addPackage($this);
}
return $this;
}
public function removeContainer(Container $container): self
{
if ($this->containers->removeElement($container)) {
$container->removePackage($this);
}
return $this;
}
/**
* @return Collection<int, Expeditable>
*/
public function getItems(): Collection
{
return $this->items;
}
public function addItem(Expeditable $item): self
{
if (!$this->items->contains($item)) {
$this->items->add($item);
}
return $this;
}
public function removeItem(Expeditable $item): self
{
$this->items->removeElement($item);
return $this;
}
public function getDestinationRepacking(): ?Repacking
{
return $this->destinationRepacking;
}
public function setDestinationRepacking(?Repacking $destinationRepacking): static
{
$this->destinationRepacking = $destinationRepacking;
return $this;
}
public function getSourceRepacking(): ?Repacking
{
return $this->sourceRepacking;
}
public function setSourceRepacking(?Repacking $sourceRepacking): static
{
$this->sourceRepacking = $sourceRepacking;
return $this;
}
/**
* @return Collection<int, PackageMovement>
*/
public function getMovements(): Collection
{
return $this->movements;
}
public function addMovement(PackageMovement $movement): static
{
if (!$this->movements->contains($movement)) {
$this->movements->add($movement);
$movement->setPackage($this);
}
return $this;
}
public function removeMovement(PackageMovement $movement): static
{
if ($this->movements->removeElement($movement)) {
// set the owning side to null (unless already changed)
if ($movement->getPackage() === $this) {
$movement->setPackage(null);
}
}
return $this;
}
/**
* @return Collection<int, File>
*/
public function getAttachments(): Collection
{
return $this->attachments;
}
public function addAttachment(File $attachment): self
{
if (!$this->attachments->contains($attachment)) {
$this->attachments->add($attachment);
}
return $this;
}
public function removeAttachment(File $attachment): self
{
$this->attachments->removeElement($attachment);
return $this;
}
}