src/Entity/Expediting/Expeditable.php line 46

  1. <?php
  2. namespace App\Entity\Expediting;
  3. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  4. use ApiPlatform\Metadata\ApiFilter;
  5. use App\Doctrine\Type\Expediting\ExpeditableStatus;
  6. use App\Entity\Common as Common;
  7. use App\Entity\Common\Company;
  8. use App\Entity\File\File;
  9. use App\Entity\Sales\Asset;
  10. use App\Validator\IsValidEnum\IsValidEnum;
  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 Gedmo\Mapping\Annotation as Gedmo;
  16. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  17. use Symfony\Component\Uid\Ulid;
  18. use Symfony\Component\Validator\Constraints as Assert;
  19. #[ORM\Table(name'expediting_item')]
  20. #[ORM\Index(columns: ['item_id'], name'expediting_item_item_id_idx')]
  21. #[ORM\Index(columns: ['order_id'], name'expediting_item_order_id_idx')]
  22. #[ORM\Index(columns: ['line_item_id'], name'expediting_item_line_item_id_idx')]
  23. #[ORM\Index(columns: ['customer_id'], name'expediting_item_customer_id_idx')]
  24. #[ORM\Index(columns: ['asset_id'], name'expediting_item_asset_id_idx')]
  25. #[ORM\Index(columns: ['flow_id'], name'expediting_item_flow_id_idx')]
  26. #[ORM\Index(columns: ['created_by'], name'expediting_item_created_by_idx')]
  27. #[ORM\Index(columns: ['updated_by'], name'expediting_item_updated_by_idx')]
  28. #[ORM\UniqueConstraint(name'expediting_item_slug_key'columns: ['slug'])]
  29. #[ORM\UniqueConstraint(name'expediting_item_reference_key'columns: ['reference'])]
  30. #[ORM\UniqueConstraint(name'expediting_item_identifier_key'columns: ['identifier'])]
  31. #[ORM\InheritanceType('SINGLE_TABLE')]
  32. #[ORM\DiscriminatorColumn(name'type'type'string')]
  33. #[ORM\DiscriminatorMap([
  34.     'PART' => Part::class,
  35.     'ITEM' => Item::class,
  36.     'DOCUMENT' => Document::class,
  37. ])]
  38. #[ORM\Entity]
  39. #[UniqueEntity(fields: ['reference'])]
  40. #[ApiFilter(SearchFilter::class, properties: [
  41.     'order.number' => 'ipartial',
  42. ])]
  43. abstract class Expeditable
  44. {
  45.     use Common\Blameable;
  46.     use Common\Trackable;
  47.     #[ORM\Id]
  48.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  49.     #[ORM\SequenceGenerator(sequenceName'expediting_item_id_seq')]
  50.     #[ORM\Column(typeTypes::INTEGER)]
  51.     protected ?int $id null;
  52.     #[Assert\Ulid]
  53.     #[Assert\NotNull]
  54.     #[ORM\Column(type'ulid'uniquetrue)]
  55.     protected ?Ulid $identifier null;
  56.     #[Gedmo\Slug(fields: ['reference'])]
  57.     #[ORM\Column(typeTypes::STRING)]
  58.     protected string $slug;
  59.     #[Assert\Type(typeTypes::STRING)]
  60.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  61.     protected ?string $reference null;
  62.     #[Assert\Type(typeTypes::STRING)]
  63.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  64.     protected ?string $supplierDescription null;
  65.     #[Assert\Type(typeTypes::STRING)]
  66.     #[ORM\Column(typeTypes::STRINGnullabletrue)]
  67.     protected ?string $clientDescription null;
  68.     #[IsValidEnum(enumExpeditableStatus::class)]
  69.     #[ORM\Column(typeTypes::STRINGenumTypeExpeditableStatus::class)]
  70.     protected ?ExpeditableStatus $status null;
  71.     #[Assert\NotNull]
  72.     #[ORM\ManyToOne(targetEntityCompany::class)]
  73.     #[ORM\JoinColumn(name'customer_id'nullablefalse)]
  74.     protected ?Company $customer null;
  75.     #[ORM\ManyToOne(targetEntityAsset::class)]
  76.     #[ORM\JoinColumn(name'asset_id')]
  77.     protected ?Asset $asset null;
  78.     /** @var Collection<int, Package> */
  79.     #[ORM\ManyToMany(targetEntityPackage::class, mappedBy'items'cascade: ['remove'])]
  80.     protected Collection $packages;
  81.     /** @var Collection<int, File> */
  82.     #[ORM\ManyToMany(targetEntityFile::class, cascade: ['persist''remove'])]
  83.     #[ORM\JoinTable(name'expediting_item_file_map')]
  84.     #[ORM\JoinColumn(name'item_id')]
  85.     #[ORM\InverseJoinColumn(name'file_id')]
  86.     #[ORM\OrderBy(['id' => 'ASC'])]
  87.     private Collection $attachments;
  88.     public function __construct()
  89.     {
  90.         $this->identifier = new Ulid();
  91.         $this->packages = new ArrayCollection();
  92.         $this->attachments = new ArrayCollection();
  93.     }
  94.     public function getId(): ?int
  95.     {
  96.         return $this->id;
  97.     }
  98.     public function getIdentifier(): ?Ulid
  99.     {
  100.         return $this->identifier;
  101.     }
  102.     public function setIdentifier(Ulid $identifier): self
  103.     {
  104.         $this->identifier $identifier;
  105.         return $this;
  106.     }
  107.     public function getSlug(): ?string
  108.     {
  109.         return $this->slug;
  110.     }
  111.     public function setSlug(string $slug): self
  112.     {
  113.         $this->slug $slug;
  114.         return $this;
  115.     }
  116.     public function getReference(): ?string
  117.     {
  118.         return $this->reference;
  119.     }
  120.     public function setReference(?string $reference): self
  121.     {
  122.         $this->reference $reference;
  123.         return $this;
  124.     }
  125.     public function getSupplierDescription(): ?string
  126.     {
  127.         return $this->supplierDescription;
  128.     }
  129.     public function setSupplierDescription(?string $supplierDescription): self
  130.     {
  131.         $this->supplierDescription $supplierDescription;
  132.         return $this;
  133.     }
  134.     public function getClientDescription(): ?string
  135.     {
  136.         return $this->clientDescription;
  137.     }
  138.     public function setClientDescription(?string $clientDescription): self
  139.     {
  140.         $this->clientDescription $clientDescription;
  141.         return $this;
  142.     }
  143.     public function getStatus(): ?ExpeditableStatus
  144.     {
  145.         return $this->status;
  146.     }
  147.     public function setStatus(?ExpeditableStatus $status): self
  148.     {
  149.         $this->status $status;
  150.         return $this;
  151.     }
  152.     public function getCustomer(): ?Company
  153.     {
  154.         return $this->customer;
  155.     }
  156.     public function setCustomer(?Company $customer): self
  157.     {
  158.         $this->customer $customer;
  159.         return $this;
  160.     }
  161.     public function getAsset(): ?Asset
  162.     {
  163.         return $this->asset;
  164.     }
  165.     public function setAsset(?Asset $asset): self
  166.     {
  167.         $this->asset $asset;
  168.         return $this;
  169.     }
  170.     /**
  171.      * @return Collection<int, Package>
  172.      */
  173.     public function getPackages(): Collection
  174.     {
  175.         return $this->packages;
  176.     }
  177.     public function addPackage(Package $package): self
  178.     {
  179.         if (!$this->packages->contains($package)) {
  180.             $this->packages->add($package);
  181.             $package->addItem($this);
  182.         }
  183.         return $this;
  184.     }
  185.     public function removePackage(Package $package): self
  186.     {
  187.         if ($this->packages->removeElement($package)) {
  188.             $package->removeItem($this);
  189.         }
  190.         return $this;
  191.     }
  192.     /**
  193.      * @return Collection<int, File>
  194.      */
  195.     public function getAttachments(): Collection
  196.     {
  197.         return $this->attachments;
  198.     }
  199.     public function addAttachment(File $attachment): self
  200.     {
  201.         if (!$this->attachments->contains($attachment)) {
  202.             $this->attachments->add($attachment);
  203.         }
  204.         return $this;
  205.     }
  206.     public function removeAttachment(File $attachment): self
  207.     {
  208.         $this->attachments->removeElement($attachment);
  209.         return $this;
  210.     }
  211. }