src/Entity/Inventory/PackageMovement.php line 41

  1. <?php
  2. namespace App\Entity\Inventory;
  3. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  4. use ApiPlatform\Metadata\ApiFilter;
  5. use ApiPlatform\Metadata\ApiProperty;
  6. use App\Entity\Common as Common;
  7. use App\Entity\Expediting\Package;
  8. use App\Entity\Expediting\Repacking;
  9. use App\Entity\Expediting\ShippingSegment;
  10. use DateTimeInterface;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Doctrine\DBAL\Types\Types;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use Symfony\Component\Uid\Ulid;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  18. #[ORM\Table(name'inventory_package_movement')]
  19. #[ORM\Index(columns: ['warehouse_id'], name'inventory_package_movement_warehouse_id_idx')]
  20. #[ORM\Index(columns: ['package_id'], name'inventory_package_movement_package_id_idx')]
  21. #[ORM\Index(columns: ['shipping_segment_id'], name'inventory_package_movement_shipping_segment_id_idx')]
  22. #[ORM\Index(columns: ['repacking_id'], name'inventory_package_movement_repacking_id_idx')]
  23. #[ORM\Index(columns: ['exit_id'], name'inventory_package_movement_exit_id_idx')]
  24. #[ORM\Index(columns: ['created_by'], name'inventory_package_movement_created_by_idx')]
  25. #[ORM\Index(columns: ['updated_by'], name'inventory_package_movement_updated_by_idx')]
  26. #[ORM\UniqueConstraint(name'inventory_package_movement_identifier_key'columns: ['identifier'])]
  27. #[ORM\InheritanceType('SINGLE_TABLE')]
  28. #[ORM\DiscriminatorColumn(name'type')]
  29. #[ORM\DiscriminatorMap([
  30.     'ENTRY' => PackageStockEntry::class,
  31.     'EXIT' => PackageStockExit::class,
  32. ])]
  33. #[ORM\Entity]
  34. #[ApiFilter(SearchFilter::class, properties: [
  35.     'package.reference' => 'ipartial',
  36.     'package.items.order.number' => 'ipartial',
  37. ])]
  38. Abstract class PackageMovement
  39. {
  40.     use Common\Blameable;
  41.     use Common\Trackable;
  42.     #[ORM\Id]
  43.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  44.     #[ORM\SequenceGenerator(sequenceName'inventory_package_movement_id_seq')]
  45.     #[ORM\Column(typeTypes::INTEGER)]
  46.     private ?int $id null;
  47.     #[Assert\Ulid]
  48.     #[Assert\NotNull]
  49.     #[ORM\Column(type'ulid'uniquetrue)]
  50.     protected ?Ulid $identifier null;
  51.     #[ApiFilter(SearchFilter::class, strategy'exact')]
  52.     #[ORM\ManyToOne(targetEntityWarehouse::class, inversedBy'movements')]
  53.     #[ORM\JoinColumn(name'warehouse_id'referencedColumnName'id'nullablefalse)]
  54.     protected ?Warehouse $warehouse null;
  55.     #[ApiProperty(readableLinktrue)]
  56.     #[ORM\ManyToOne(targetEntityPackage::class, inversedBy'movements')]
  57.     #[ORM\JoinColumn(name'package_id'referencedColumnName'id'nullablefalse)]
  58.     protected ?Package $package null;
  59.     #[ORM\ManyToOne(targetEntityShippingSegment::class, inversedBy'movements')]
  60.     #[ORM\JoinColumn(name'shipping_segment_id'referencedColumnName'id')]
  61.     protected ?ShippingSegment $shippingSegment null;
  62.     #[ORM\ManyToOne(targetEntityRepacking::class, inversedBy'movements')]
  63.     #[ORM\JoinColumn(name'repacking_id'referencedColumnName'id')]
  64.     protected ?Repacking $repacking null;
  65.     #[Assert\Type(typeDateTimeInterface::class)]
  66.     #[ORM\Column(typeTypes::DATETIMETZ_MUTABLEnullablefalse)]
  67.     protected ?DateTimeInterface $completedAt null;
  68.     /** @var Collection<int, ItemMovement> */
  69.     #[ORM\OneToMany(mappedBy'packageMovement'targetEntityItemMovement::class)]
  70.     private Collection $itemsMovements;
  71.     public function __construct()
  72.     {
  73.         $this->identifier = new Ulid();
  74.         $this->itemsMovements = new ArrayCollection();
  75.     }
  76.     #[Assert\Callback]
  77.     public function validate(ExecutionContextInterface $context$payload): void
  78.     {
  79.         if (empty($this->shipment) && empty($this->repacking)) {
  80.             $context->buildViolation('Package movement must be associated only with either, a shipment, or a repacking')
  81.                 ->atPath('shipment')
  82.                 ->addViolation();
  83.             $context->buildViolation('Package movement must be associated only with either, a shipment, or a repacking')
  84.                 ->atPath('repacking')
  85.                 ->addViolation();
  86.         }
  87.     }
  88.     public function getId(): ?int
  89.     {
  90.         return $this->id;
  91.     }
  92.     public function getIdentifier(): ?Ulid
  93.     {
  94.         return $this->identifier;
  95.     }
  96.     public function setIdentifier(Ulid $identifier): static
  97.     {
  98.         $this->identifier $identifier;
  99.         return $this;
  100.     }
  101.     public function getCompletedAt(): ?DateTimeInterface
  102.     {
  103.         return $this->completedAt;
  104.     }
  105.     public function setCompletedAt(DateTimeInterface $completedAt): static
  106.     {
  107.         $this->completedAt $completedAt;
  108.         return $this;
  109.     }
  110.     public function getWarehouse(): ?Warehouse
  111.     {
  112.         return $this->warehouse;
  113.     }
  114.     public function setWarehouse(?Warehouse $warehouse): static
  115.     {
  116.         $this->warehouse $warehouse;
  117.         return $this;
  118.     }
  119.     public function getPackage(): ?Package
  120.     {
  121.         return $this->package;
  122.     }
  123.     public function setPackage(?Package $package): static
  124.     {
  125.         $this->package $package;
  126.         return $this;
  127.     }
  128.     public function getShippingSegment(): ?ShippingSegment
  129.     {
  130.         return $this->shippingSegment;
  131.     }
  132.     public function setShippingSegment(?ShippingSegment $shippingSegment): static
  133.     {
  134.         $this->shippingSegment $shippingSegment;
  135.         return $this;
  136.     }
  137.     public function getRepacking(): ?Repacking
  138.     {
  139.         return $this->repacking;
  140.     }
  141.     public function setRepacking(?Repacking $repacking): static
  142.     {
  143.         $this->repacking $repacking;
  144.         return $this;
  145.     }
  146.     /**
  147.      * @return Collection<int, ItemMovement>
  148.      */
  149.     public function getItemsMovements(): Collection
  150.     {
  151.         return $this->itemsMovements;
  152.     }
  153.     public function addItemsMovement(ItemMovement $itemsMovement): static
  154.     {
  155.         if (!$this->itemsMovements->contains($itemsMovement)) {
  156.             $this->itemsMovements->add($itemsMovement);
  157.             $itemsMovement->setPackageMovement($this);
  158.         }
  159.         return $this;
  160.     }
  161.     public function removeItemsMovement(ItemMovement $itemsMovement): static
  162.     {
  163.         if ($this->itemsMovements->removeElement($itemsMovement)) {
  164.             // set the owning side to null (unless already changed)
  165.             if ($itemsMovement->getPackageMovement() === $this) {
  166.                 $itemsMovement->setPackageMovement(null);
  167.             }
  168.         }
  169.         return $this;
  170.     }
  171. }