src/Entity/Expediting/Package.php line 65

  1. <?php
  2. namespace App\Entity\Expediting;
  3. use ApiPlatform\Metadata\ApiProperty;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use ApiPlatform\Metadata\Delete;
  6. use ApiPlatform\Metadata\Get;
  7. use ApiPlatform\Metadata\GetCollection;
  8. use ApiPlatform\Metadata\Link;
  9. use ApiPlatform\Metadata\Patch;
  10. use ApiPlatform\Metadata\Post;
  11. use ApiPlatform\Metadata\Put;
  12. use App\Doctrine\Type\Expediting\CasingMaterial;
  13. use App\Doctrine\Type\Expediting\CasingType;
  14. use App\Doctrine\Type\Expediting\ExpeditableStatus;
  15. use App\Dto\Expediting\PackageSurveyInput;
  16. use App\Entity\Common as Common;
  17. use App\Entity\File\File;
  18. use App\Entity\Inventory\PackageMovement;
  19. use App\Processor\Expediting\PackageSurveyInputProcessor;
  20. use App\Validator\IsValidEnum\IsValidEnum;
  21. use Doctrine\Common\Collections\ArrayCollection;
  22. use Doctrine\Common\Collections\Collection;
  23. use Doctrine\DBAL\Types\Types;
  24. use Doctrine\ORM\Mapping as ORM;
  25. use Gedmo\Mapping\Annotation as Gedmo;
  26. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  27. use Symfony\Component\Serializer\Annotation\Ignore;
  28. use Symfony\Component\Uid\Ulid;
  29. use Symfony\Component\Validator\Constraints as Assert;
  30. #[ORM\Table(name'expediting_package')]
  31. #[ORM\Index(columns: ['destination_repacking_id'], name'expediting_package_destination_repacking_id_idx')]
  32. #[ORM\Index(columns: ['source_repacking_id'], name'expediting_package_source_repacking_id_idx')]
  33. #[ORM\Index(columns: ['created_by'], name'expediting_package_created_by_idx')]
  34. #[ORM\Index(columns: ['updated_by'], name'expediting_package_updated_by_idx')]
  35. #[ORM\UniqueConstraint(name'expediting_package_slug_key'columns: ['slug'])]
  36. #[ORM\UniqueConstraint(name'expediting_package_reference_key'columns: ['reference'])]
  37. #[ORM\UniqueConstraint(name'expediting_package_identifier_key'columns: ['identifier'])]
  38. #[ORM\Entity]
  39. #[UniqueEntity(fields: ['reference'])]
  40. #[ApiResource(
  41.     operations: [
  42.         new Get(),
  43.         new GetCollection(),
  44.         new Post(),
  45.         new Put(),
  46.         new Patch(),
  47.         new Delete(),
  48.         new Post(
  49.             uriTemplate'/packages/survey',
  50.             inputFormats: ['json' => ['application/json'], 'multipart' => ['multipart/form-data']],
  51.             inputPackageSurveyInput::class,
  52.             processorPackageSurveyInputProcessor::class
  53.         ),
  54.     ],
  55.     routePrefix'/expediting'
  56. )]
  57. #[ApiResource(
  58.     uriTemplate'/expediting/shipments/{slug}/packages',
  59.     operations: [new GetCollection()],
  60.     uriVariables: ['slug' => new Link(fromProperty'packages'fromClassShipment::class)],
  61. )]
  62. class Package
  63. {
  64.     use Common\Blameable;
  65.     use Common\Trackable;
  66.     use Shippable;
  67.     #[ORM\Id]
  68.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  69.     #[ORM\SequenceGenerator(sequenceName'expediting_package_id_seq')]
  70.     #[ORM\Column(typeTypes::INTEGER)]
  71.     #[ApiProperty(identifierfalse)]
  72.     private ?int $id null;
  73.     #[Assert\Ulid]
  74.     #[Assert\NotNull]
  75.     #[ORM\Column(type'ulid'uniquetrue)]
  76.     private ?Ulid $identifier null;
  77.     #[Gedmo\Slug(fields: ['reference'])]
  78.     #[ORM\Column(typeTypes::STRING)]
  79.     #[ApiProperty(identifiertrue)]
  80.     private ?string $slug null;
  81.     #[Assert\NotBlank]
  82.     #[Assert\Type(typeTypes::STRING)]
  83.     #[ORM\Column(typeTypes::STRING)]
  84.     private ?string $reference null;
  85.     #[Assert\NotBlank]
  86.     #[Assert\Type(typeTypes::STRING)]
  87.     #[ORM\Column(typeTypes::STRING)]
  88.     private ?string $packageNumber null;
  89.     #[Assert\Type(typeTypes::FLOAT)]
  90.     #[ORM\Column(typeTypes::DECIMALprecision18scale3nullabletrue)]
  91.     private ?float $length null;
  92.     #[Assert\Type(typeTypes::FLOAT)]
  93.     #[ORM\Column(typeTypes::DECIMALprecision18scale3nullabletrue)]
  94.     private ?float $width null;
  95.     #[Assert\Type(typeTypes::FLOAT)]
  96.     #[ORM\Column(typeTypes::DECIMALprecision18scale3nullabletrue)]
  97.     private ?float $height null;
  98.     #[Assert\Type(typeTypes::FLOAT)]
  99.     #[ORM\Column(typeTypes::DECIMALprecision18scale3nullabletrue)]
  100.     private ?float $weight null;
  101.     #[Assert\Type(typeTypes::FLOAT)]
  102.     #[ORM\Column(typeTypes::DECIMALprecision18scale3nullabletrue)]
  103.     private ?float $shippingWeight null;
  104.     #[Assert\NotNull]
  105.     #[Assert\Type(typeTypes::BOOLEAN)]
  106.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  107.     private ?bool $openable false;
  108.     #[Assert\NotNull]
  109.     #[Assert\Type(typeTypes::BOOLEAN)]
  110.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  111.     private ?bool $destroyed false;
  112.     #[IsValidEnum(enumCasingType::class)]
  113.     #[ORM\Column(typeTypes::STRINGnullabletrueenumTypeCasingType::class)]
  114.     private ?CasingType $casingType null;
  115.     #[IsValidEnum(enumCasingMaterial::class)]
  116.     #[ORM\Column(typeTypes::STRINGnullabletrueenumTypeCasingMaterial::class)]
  117.     private ?CasingMaterial $casingMaterial null;
  118.     #[Assert\NotNull]
  119.     #[IsValidEnum(enumExpeditableStatus::class)]
  120.     #[ORM\Column(typeTypes::STRINGenumTypeExpeditableStatus::class)]
  121.     private ?ExpeditableStatus $status null;
  122.     #[ORM\ManyToOne(targetEntityRepacking::class, inversedBy'inputs')]
  123.     #[ORM\JoinColumn(name'destination_repacking_id')]
  124.     private ?Repacking $destinationRepacking null;
  125.     #[ORM\ManyToOne(targetEntityRepacking::class, inversedBy'outputs')]
  126.     #[ORM\JoinColumn(name'source_repacking_id')]
  127.     private ?Repacking $sourceRepacking null;
  128.     /** @var Collection<int, Shipment> */
  129.     #[ORM\ManyToMany(targetEntityShipment::class, mappedBy'packages')]
  130.     private Collection $shipments;
  131.     /** @var Collection<int, Container> */
  132.     #[ORM\ManyToMany(targetEntityContainer::class, mappedBy'packages')]
  133.     private Collection $containers;
  134.     /** @var Collection<int, PackageMovement> */
  135.     #[ORM\OneToMany(mappedBy'package'targetEntityPackageMovement::class)]
  136.     #[ORM\OrderBy(['id' => 'DESC'])]
  137.     #[Ignore]
  138.     private Collection $movements;
  139.     /** @var Collection<int, Expeditable> */
  140.     #[ORM\ManyToMany(targetEntityExpeditable::class, inversedBy'packages')]
  141.     #[ORM\JoinTable(name'expediting_package_item_map')]
  142.     #[ORM\JoinColumn(name'package_id')]
  143.     #[ORM\InverseJoinColumn(name'item_id')]
  144.     private Collection $items;
  145.     /** @var Collection<int, File> */
  146.     #[ORM\ManyToMany(targetEntityFile::class, cascade: ['persist''remove'])]
  147.     #[ORM\JoinTable(name'expediting_package_file_map')]
  148.     #[ORM\JoinColumn(name'package_id')]
  149.     #[ORM\InverseJoinColumn(name'file_id')]
  150.     #[ORM\OrderBy(['id' => 'ASC'])]
  151.     private Collection $attachments;
  152.     public function __construct()
  153.     {
  154.         $this->identifier = new Ulid();
  155.         $this->shipments = new ArrayCollection();
  156.         $this->containers = new ArrayCollection();
  157.         $this->movements = new ArrayCollection();
  158.         $this->items = new ArrayCollection();
  159.         $this->attachments = new ArrayCollection();
  160.     }
  161.     public function getId(): ?int
  162.     {
  163.         return $this->id;
  164.     }
  165.     public function getIdentifier(): ?Ulid
  166.     {
  167.         return $this->identifier;
  168.     }
  169.     public function setIdentifier(Ulid $identifier): self
  170.     {
  171.         $this->identifier $identifier;
  172.         return $this;
  173.     }
  174.     public function getSlug(): ?string
  175.     {
  176.         return $this->slug;
  177.     }
  178.     public function setSlug(string $slug): self
  179.     {
  180.         $this->slug $slug;
  181.         return $this;
  182.     }
  183.     public function getReference(): ?string
  184.     {
  185.         return $this->reference;
  186.     }
  187.     public function setReference(string $reference): self
  188.     {
  189.         $this->reference $reference;
  190.         return $this;
  191.     }
  192.     public function getPackageNumber(): ?string
  193.     {
  194.         return $this->packageNumber;
  195.     }
  196.     public function setPackageNumber(string $packageNumber): self
  197.     {
  198.         $this->packageNumber $packageNumber;
  199.         return $this;
  200.     }
  201.     public function getWidth(): ?string
  202.     {
  203.         return (string) $this->width;
  204.     }
  205.     public function setWidth(float|string|null $width): self
  206.     {
  207.         $this->width null === $width null : (float) $width;
  208.         $this->setShippingWeight();
  209.         return $this;
  210.     }
  211.     public function getLength(): ?string
  212.     {
  213.         return (string) $this->length;
  214.     }
  215.     public function setLength(float|string|null $length): self
  216.     {
  217.         $this->length null === $length null : (float) $length;
  218.         $this->setShippingWeight();
  219.         return $this;
  220.     }
  221.     public function getHeight(): ?string
  222.     {
  223.         return (string) $this->height;
  224.     }
  225.     public function setHeight(float|string|null $height): self
  226.     {
  227.         $this->height null === $height null : (float) $height;
  228.         $this->setShippingWeight();
  229.         return $this;
  230.     }
  231.     public function getWeight(): ?string
  232.     {
  233.         return (string) $this->weight;
  234.     }
  235.     public function setWeight(float|string|null $weight): self
  236.     {
  237.         $this->weight null === $weight null : (float) $weight;
  238.         return $this;
  239.     }
  240.     public function getShippingWeight(): ?string
  241.     {
  242.         return (string) $this->shippingWeight;
  243.     }
  244.     public function setShippingWeight(): self
  245.     {
  246.         $volume = ($this->width $this->length $this->height) / 6_000;
  247.         $shippingWeight max($this->weight$volume);
  248.         $this->shippingWeight $shippingWeight;
  249.         return $this;
  250.     }
  251.     public function isOpenable(): ?bool
  252.     {
  253.         return $this->openable;
  254.     }
  255.     public function setOpenable(bool $openable): self
  256.     {
  257.         $this->openable $openable;
  258.         return $this;
  259.     }
  260.     public function isDestroyed(): ?bool
  261.     {
  262.         return $this->destroyed;
  263.     }
  264.     public function setDestroyed(bool $destroyed): self
  265.     {
  266.         $this->destroyed $destroyed;
  267.         return $this;
  268.     }
  269.     public function getCasingType(): ?CasingType
  270.     {
  271.         return $this->casingType;
  272.     }
  273.     public function setCasingType(?CasingType $casingType): self
  274.     {
  275.         $this->casingType $casingType;
  276.         return $this;
  277.     }
  278.     public function getCasingMaterial(): ?CasingMaterial
  279.     {
  280.         return $this->casingMaterial;
  281.     }
  282.     public function setCasingMaterial(?CasingMaterial $casingMaterial): self
  283.     {
  284.         $this->casingMaterial $casingMaterial;
  285.         return $this;
  286.     }
  287.     public function getStatus(): ?ExpeditableStatus
  288.     {
  289.         return $this->status;
  290.     }
  291.     public function setStatus(?ExpeditableStatus $status): self
  292.     {
  293.         $this->status $status;
  294.         return $this;
  295.     }
  296.     /**
  297.      * @return Collection<int, Shipment>
  298.      */
  299.     public function getShipments(): Collection
  300.     {
  301.         return $this->shipments;
  302.     }
  303.     public function addShipment(Shipment $shipment): self
  304.     {
  305.         if (!$this->shipments->contains($shipment)) {
  306.             $this->shipments->add($shipment);
  307.             $shipment->addPackage($this);
  308.         }
  309.         return $this;
  310.     }
  311.     public function removeShipment(Shipment $shipment): self
  312.     {
  313.         if ($this->shipments->removeElement($shipment)) {
  314.             $shipment->removePackage($this);
  315.         }
  316.         return $this;
  317.     }
  318.     /**
  319.      * @return Collection<int, Container>
  320.      */
  321.     public function getContainers(): Collection
  322.     {
  323.         return $this->containers;
  324.     }
  325.     public function addContainer(Container $container): self
  326.     {
  327.         if (!$this->containers->contains($container)) {
  328.             $this->containers->add($container);
  329.             $container->addPackage($this);
  330.         }
  331.         return $this;
  332.     }
  333.     public function removeContainer(Container $container): self
  334.     {
  335.         if ($this->containers->removeElement($container)) {
  336.             $container->removePackage($this);
  337.         }
  338.         return $this;
  339.     }
  340.     /**
  341.      * @return Collection<int, Expeditable>
  342.      */
  343.     public function getItems(): Collection
  344.     {
  345.         return $this->items;
  346.     }
  347.     public function addItem(Expeditable $item): self
  348.     {
  349.         if (!$this->items->contains($item)) {
  350.             $this->items->add($item);
  351.         }
  352.         return $this;
  353.     }
  354.     public function removeItem(Expeditable $item): self
  355.     {
  356.         $this->items->removeElement($item);
  357.         return $this;
  358.     }
  359.     public function getDestinationRepacking(): ?Repacking
  360.     {
  361.         return $this->destinationRepacking;
  362.     }
  363.     public function setDestinationRepacking(?Repacking $destinationRepacking): static
  364.     {
  365.         $this->destinationRepacking $destinationRepacking;
  366.         return $this;
  367.     }
  368.     public function getSourceRepacking(): ?Repacking
  369.     {
  370.         return $this->sourceRepacking;
  371.     }
  372.     public function setSourceRepacking(?Repacking $sourceRepacking): static
  373.     {
  374.         $this->sourceRepacking $sourceRepacking;
  375.         return $this;
  376.     }
  377.     /**
  378.      * @return Collection<int, PackageMovement>
  379.      */
  380.     public function getMovements(): Collection
  381.     {
  382.         return $this->movements;
  383.     }
  384.     public function addMovement(PackageMovement $movement): static
  385.     {
  386.         if (!$this->movements->contains($movement)) {
  387.             $this->movements->add($movement);
  388.             $movement->setPackage($this);
  389.         }
  390.         return $this;
  391.     }
  392.     public function removeMovement(PackageMovement $movement): static
  393.     {
  394.         if ($this->movements->removeElement($movement)) {
  395.             // set the owning side to null (unless already changed)
  396.             if ($movement->getPackage() === $this) {
  397.                 $movement->setPackage(null);
  398.             }
  399.         }
  400.         return $this;
  401.     }
  402.     /**
  403.      * @return Collection<int, File>
  404.      */
  405.     public function getAttachments(): Collection
  406.     {
  407.         return $this->attachments;
  408.     }
  409.     public function addAttachment(File $attachment): self
  410.     {
  411.         if (!$this->attachments->contains($attachment)) {
  412.             $this->attachments->add($attachment);
  413.         }
  414.         return $this;
  415.     }
  416.     public function removeAttachment(File $attachment): self
  417.     {
  418.         $this->attachments->removeElement($attachment);
  419.         return $this;
  420.     }
  421. }