src/Entity/Inventory/Withdrawal.php line 27

  1. <?php
  2. namespace App\Entity\Inventory;
  3. use ApiPlatform\Metadata\ApiProperty;
  4. use App\Doctrine\Type\Inventory\WithdrawalStatus;
  5. use App\Entity\Common as Common;
  6. use App\Entity\Identity\User;
  7. use App\Validator\IsValidEnum\IsValidEnum;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\DBAL\Types\Types;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Gedmo\Mapping\Annotation as Gedmo;
  13. use Symfony\Component\Uid\Ulid;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. #[ORM\Table(name'inventory_withdrawal')]
  16. #[ORM\Index(columns: ['warehouse_id'], name'inventory_withdrawal_warehouse_id_idx')]
  17. #[ORM\Index(columns: ['beneficiary_id'], name'inventory_withdrawal_beneficiary_id_idx')]
  18. #[ORM\Index(columns: ['created_by'], name'inventory_withdrawal_created_by_idx')]
  19. #[ORM\Index(columns: ['updated_by'], name'inventory_withdrawal_updated_by_idx')]
  20. #[ORM\UniqueConstraint(name'inventory_withdrawal_slug_key'columns: ['slug'])]
  21. #[ORM\UniqueConstraint(name'inventory_withdrawal_reference_key'columns: ['reference'])]
  22. #[ORM\UniqueConstraint(name'inventory_withdrawal_identifier_key'columns: ['identifier'])]
  23. #[ORM\Entity]
  24. class Withdrawal
  25. {
  26.     use Common\Blameable;
  27.     use Common\Trackable;
  28.     #[ORM\Id]
  29.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  30.     #[ORM\SequenceGenerator(sequenceName'inventory_withdrawal_id_seq')]
  31.     #[ORM\Column(typeTypes::INTEGER)]
  32.     private ?int $id null;
  33.     #[Assert\Ulid]
  34.     #[Assert\NotNull]
  35.     #[ORM\Column(type'ulid'uniquetrue)]
  36.     private ?Ulid $identifier null;
  37.     #[Gedmo\Slug(fields: ['reference'])]
  38.     #[ORM\Column(typeTypes::STRING)]
  39.     #[ApiProperty(identifiertrue)]
  40.     private ?string $slug null;
  41.     #[Assert\NotBlank]
  42.     #[ORM\Column(typeTypes::STRING)]
  43.     private ?string $reference null;
  44.     #[Assert\NotNull]
  45.     #[ORM\ManyToOne(targetEntityWarehouse::class, inversedBy'withdrawals')]
  46.     #[ORM\JoinColumn(name'warehouse_id'nullablefalse)]
  47.     private ?Warehouse $warehouse null;
  48.     #[Assert\NotNull]
  49.     #[ORM\ManyToOne(targetEntityUser::class)]
  50.     #[ORM\JoinColumn(name'beneficiary_id'nullablefalse)]
  51.     private ?User $beneficiary null;
  52.     #[Assert\NotNull]
  53.     #[IsValidEnum(enumWithdrawalStatus::class)]
  54.     #[ORM\Column(typeTypes::STRINGenumTypeWithdrawalStatus::class, options: ['default' => 'REQUESTED'])]
  55.     private ?WithdrawalStatus $status WithdrawalStatus::REQUESTED;
  56.     /** @var Collection<int, WithdrawalItem> */
  57.     #[ORM\OneToMany(mappedBy'withdrawal'targetEntityWithdrawalItem::class)]
  58.     private Collection $items;
  59.     /** @var Collection<int, ItemStockExit> */
  60.     #[ORM\OneToMany(mappedBy'withdrawal'targetEntityItemStockExit::class)]
  61.     private Collection $itemsMovements;
  62.     public function __construct()
  63.     {
  64.         $this->identifier = new Ulid();
  65.         $this->items = new ArrayCollection();
  66.         $this->itemsMovements = new ArrayCollection();
  67.     }
  68.     public function getId(): ?int
  69.     {
  70.         return $this->id;
  71.     }
  72.     public function getIdentifier(): ?Ulid
  73.     {
  74.         return $this->identifier;
  75.     }
  76.     public function setIdentifier(Ulid $identifier): static
  77.     {
  78.         $this->identifier $identifier;
  79.         return $this;
  80.     }
  81.     public function getSlug(): ?string
  82.     {
  83.         return $this->slug;
  84.     }
  85.     public function setSlug(string $slug): static
  86.     {
  87.         $this->slug $slug;
  88.         return $this;
  89.     }
  90.     public function getReference(): ?string
  91.     {
  92.         return $this->reference;
  93.     }
  94.     public function setReference(string $reference): static
  95.     {
  96.         $this->reference $reference;
  97.         return $this;
  98.     }
  99.     public function getStatus(): ?WithdrawalStatus
  100.     {
  101.         return $this->status;
  102.     }
  103.     public function setStatus(WithdrawalStatus $status): static
  104.     {
  105.         $this->status $status;
  106.         return $this;
  107.     }
  108.     public function getWarehouse(): ?Warehouse
  109.     {
  110.         return $this->warehouse;
  111.     }
  112.     public function setWarehouse(?Warehouse $warehouse): static
  113.     {
  114.         $this->warehouse $warehouse;
  115.         return $this;
  116.     }
  117.     public function getBeneficiary(): ?User
  118.     {
  119.         return $this->beneficiary;
  120.     }
  121.     public function setBeneficiary(?User $beneficiary): static
  122.     {
  123.         $this->beneficiary $beneficiary;
  124.         return $this;
  125.     }
  126.     /**
  127.      * @return Collection<int, WithdrawalItem>
  128.      */
  129.     public function getItems(): Collection
  130.     {
  131.         return $this->items;
  132.     }
  133.     public function addItem(WithdrawalItem $item): static
  134.     {
  135.         if (!$this->items->contains($item)) {
  136.             $this->items->add($item);
  137.             $item->setWithdrawal($this);
  138.         }
  139.         return $this;
  140.     }
  141.     public function removeItem(WithdrawalItem $item): static
  142.     {
  143.         if ($this->items->removeElement($item)) {
  144.             // set the owning side to null (unless already changed)
  145.             if ($item->getWithdrawal() === $this) {
  146.                 $item->setWithdrawal(null);
  147.             }
  148.         }
  149.         return $this;
  150.     }
  151.     /**
  152.      * @return Collection<int, ItemStockExit>
  153.      */
  154.     public function getItemsMovements(): Collection
  155.     {
  156.         return $this->itemsMovements;
  157.     }
  158.     public function addItemsMovement(ItemStockExit $itemsMovement): static
  159.     {
  160.         if (!$this->itemsMovements->contains($itemsMovement)) {
  161.             $this->itemsMovements->add($itemsMovement);
  162.             $itemsMovement->setWithdrawal($this);
  163.         }
  164.         return $this;
  165.     }
  166.     public function removeItemsMovement(ItemStockExit $itemsMovement): static
  167.     {
  168.         if ($this->itemsMovements->removeElement($itemsMovement)) {
  169.             // set the owning side to null (unless already changed)
  170.             if ($itemsMovement->getWithdrawal() === $this) {
  171.                 $itemsMovement->setWithdrawal(null);
  172.             }
  173.         }
  174.         return $this;
  175.     }
  176. }