<?php
namespace App\Entity;
use App\Repository\StockTransferRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=StockTransferRepository::class)
* @ORM\Table(name="stock_transfer")
*/
class StockTransfer
{
public const STATUS_DRAFT = 'draft';
public const STATUS_CONFIRMED = 'confirmed';
public const STATUS_CANCELLED = 'cancelled';
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=30, unique=true)
*/
private $reference;
/**
* @ORM\ManyToOne(targetEntity=Warehouse::class, inversedBy="sourceTransfers")
* @ORM\JoinColumn(name="source_warehouse_id", referencedColumnName="id", nullable=false, onDelete="RESTRICT")
*/
private $sourceWarehouse;
/**
* @ORM\ManyToOne(targetEntity=Warehouse::class, inversedBy="targetTransfers")
* @ORM\JoinColumn(name="target_warehouse_id", referencedColumnName="id", nullable=false, onDelete="RESTRICT")
*/
private $targetWarehouse;
/**
* @ORM\Column(type="string", length=20, options={"default":"draft"})
*/
private $status = self::STATUS_DRAFT;
/**
* @ORM\Column(name="created_by", type="integer", nullable=true)
*/
private $createdBy;
/**
* @ORM\Column(name="created_at", type="datetime")
*/
private $createdAt;
/**
* @ORM\Column(name="validated_at", type="datetime", nullable=true)
*/
private $validatedAt;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $notes;
/**
* @ORM\OneToMany(targetEntity=StockTransferLine::class, mappedBy="transfer", cascade={"persist","remove"}, orphanRemoval=true)
*/
private $lines;
public function __construct()
{
$this->lines = new ArrayCollection();
$this->createdAt = new \DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function getReference(): ?string
{
return $this->reference;
}
public function setReference(string $reference): self
{
$this->reference = trim($reference);
return $this;
}
public function getSourceWarehouse(): ?Warehouse
{
return $this->sourceWarehouse;
}
public function setSourceWarehouse(?Warehouse $sourceWarehouse): self
{
$this->sourceWarehouse = $sourceWarehouse;
return $this;
}
public function getTargetWarehouse(): ?Warehouse
{
return $this->targetWarehouse;
}
public function setTargetWarehouse(?Warehouse $targetWarehouse): self
{
$this->targetWarehouse = $targetWarehouse;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
public function getCreatedBy(): ?int
{
return $this->createdBy;
}
public function setCreatedBy(?int $createdBy): self
{
$this->createdBy = $createdBy;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getValidatedAt(): ?\DateTimeInterface
{
return $this->validatedAt;
}
public function setValidatedAt(?\DateTimeInterface $validatedAt): self
{
$this->validatedAt = $validatedAt;
return $this;
}
public function getNotes(): ?string
{
return $this->notes;
}
public function setNotes(?string $notes): self
{
$this->notes = $notes !== null ? trim($notes) : null;
return $this;
}
/**
* @return Collection|StockTransferLine[]
*/
public function getLines(): Collection
{
return $this->lines;
}
public function addLine(StockTransferLine $line): self
{
if (!$this->lines->contains($line)) {
$this->lines[] = $line;
$line->setTransfer($this);
}
return $this;
}
public function removeLine(StockTransferLine $line): self
{
if ($this->lines->removeElement($line)) {
if ($line->getTransfer() === $this) {
$line->setTransfer(null);
}
}
return $this;
}
public function isDraft(): bool
{
return $this->status === self::STATUS_DRAFT;
}
public function isConfirmed(): bool
{
return $this->status === self::STATUS_CONFIRMED;
}
}