src/Entity/Inventory/Withdrawal.php line 27
<?php
namespace App\Entity\Inventory;
use ApiPlatform\Metadata\ApiProperty;
use App\Doctrine\Type\Inventory\WithdrawalStatus;
use App\Entity\Common as Common;
use App\Entity\Identity\User;
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\Component\Uid\Ulid;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Table(name: 'inventory_withdrawal')]
#[ORM\Index(columns: ['warehouse_id'], name: 'inventory_withdrawal_warehouse_id_idx')]
#[ORM\Index(columns: ['beneficiary_id'], name: 'inventory_withdrawal_beneficiary_id_idx')]
#[ORM\Index(columns: ['created_by'], name: 'inventory_withdrawal_created_by_idx')]
#[ORM\Index(columns: ['updated_by'], name: 'inventory_withdrawal_updated_by_idx')]
#[ORM\UniqueConstraint(name: 'inventory_withdrawal_slug_key', columns: ['slug'])]
#[ORM\UniqueConstraint(name: 'inventory_withdrawal_reference_key', columns: ['reference'])]
#[ORM\UniqueConstraint(name: 'inventory_withdrawal_identifier_key', columns: ['identifier'])]
#[ORM\Entity]
class Withdrawal
{
use Common\Blameable;
use Common\Trackable;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
#[ORM\SequenceGenerator(sequenceName: 'inventory_withdrawal_id_seq')]
#[ORM\Column(type: Types::INTEGER)]
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]
#[ORM\Column(type: Types::STRING)]
private ?string $reference = null;
#[Assert\NotNull]
#[ORM\ManyToOne(targetEntity: Warehouse::class, inversedBy: 'withdrawals')]
#[ORM\JoinColumn(name: 'warehouse_id', nullable: false)]
private ?Warehouse $warehouse = null;
#[Assert\NotNull]
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(name: 'beneficiary_id', nullable: false)]
private ?User $beneficiary = null;
#[Assert\NotNull]
#[IsValidEnum(enum: WithdrawalStatus::class)]
#[ORM\Column(type: Types::STRING, enumType: WithdrawalStatus::class, options: ['default' => 'REQUESTED'])]
private ?WithdrawalStatus $status = WithdrawalStatus::REQUESTED;
/** @var Collection<int, WithdrawalItem> */
#[ORM\OneToMany(mappedBy: 'withdrawal', targetEntity: WithdrawalItem::class)]
private Collection $items;
/** @var Collection<int, ItemStockExit> */
#[ORM\OneToMany(mappedBy: 'withdrawal', targetEntity: ItemStockExit::class)]
private Collection $itemsMovements;
public function __construct()
{
$this->identifier = new Ulid();
$this->items = new ArrayCollection();
$this->itemsMovements = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getIdentifier(): ?Ulid
{
return $this->identifier;
}
public function setIdentifier(Ulid $identifier): static
{
$this->identifier = $identifier;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): static
{
$this->slug = $slug;
return $this;
}
public function getReference(): ?string
{
return $this->reference;
}
public function setReference(string $reference): static
{
$this->reference = $reference;
return $this;
}
public function getStatus(): ?WithdrawalStatus
{
return $this->status;
}
public function setStatus(WithdrawalStatus $status): static
{
$this->status = $status;
return $this;
}
public function getWarehouse(): ?Warehouse
{
return $this->warehouse;
}
public function setWarehouse(?Warehouse $warehouse): static
{
$this->warehouse = $warehouse;
return $this;
}
public function getBeneficiary(): ?User
{
return $this->beneficiary;
}
public function setBeneficiary(?User $beneficiary): static
{
$this->beneficiary = $beneficiary;
return $this;
}
/**
* @return Collection<int, WithdrawalItem>
*/
public function getItems(): Collection
{
return $this->items;
}
public function addItem(WithdrawalItem $item): static
{
if (!$this->items->contains($item)) {
$this->items->add($item);
$item->setWithdrawal($this);
}
return $this;
}
public function removeItem(WithdrawalItem $item): static
{
if ($this->items->removeElement($item)) {
// set the owning side to null (unless already changed)
if ($item->getWithdrawal() === $this) {
$item->setWithdrawal(null);
}
}
return $this;
}
/**
* @return Collection<int, ItemStockExit>
*/
public function getItemsMovements(): Collection
{
return $this->itemsMovements;
}
public function addItemsMovement(ItemStockExit $itemsMovement): static
{
if (!$this->itemsMovements->contains($itemsMovement)) {
$this->itemsMovements->add($itemsMovement);
$itemsMovement->setWithdrawal($this);
}
return $this;
}
public function removeItemsMovement(ItemStockExit $itemsMovement): static
{
if ($this->itemsMovements->removeElement($itemsMovement)) {
// set the owning side to null (unless already changed)
if ($itemsMovement->getWithdrawal() === $this) {
$itemsMovement->setWithdrawal(null);
}
}
return $this;
}
}