<?php
namespace App\Entity;
use App\Enum\RestockingAction;
use App\Enum\ReturnItemCondition;
use App\Repository\SalesReturnItemRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: SalesReturnItemRepository::class)]
#[ORM\Table(name: 'sales_return_item')]
#[ORM\HasLifecycleCallbacks]
class SalesReturnItem extends BaseEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\ManyToOne(targetEntity: SalesReturn::class, inversedBy: 'items')]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
private ?SalesReturn $salesReturn = null;
#[ORM\ManyToOne(targetEntity: ProductsSold::class)]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
private ?ProductsSold $productsSold = null;
#[ORM\Column(type: Types::DECIMAL, precision: 15, scale: 4)]
private string $requestedQuantity;
#[ORM\Column(type: Types::DECIMAL, precision: 15, scale: 4) ]
private string $approvedQuantity;
#[ORM\Column(type: Types::DECIMAL, precision: 15, scale: 4)]
private string $approvedBaseQuantity;
#[ORM\Column(type: Types::DECIMAL, precision: 15, scale: 4, options: ['default' => '0.0000'])]
private string $goodQuantity = '0.0000';
#[ORM\Column(type: Types::DECIMAL, precision: 15, scale: 4, options: ['default' => '0.0000'])]
private string $goodBaseQuantity = '0.0000';
#[ORM\Column(type: Types::DECIMAL, precision: 15, scale: 4, options: ['default' => '0.0000'])]
private string $damagedQuantity = '0.0000';
#[ORM\Column(type: Types::DECIMAL, precision: 15, scale: 4, options: ['default' => '0.0000'])]
private string $damagedBaseQuantity = '0.0000';
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
private bool $restocked = false;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
private ?\DateTimeImmutable $restockedAt = null;
#[ORM\Column(name: 'item_condition', length: 32, enumType: ReturnItemCondition::class)]
private ReturnItemCondition $condition = ReturnItemCondition::PRISTINE;
#[ORM\Column(length: 32, enumType: RestockingAction::class)]
private RestockingAction $restockingAction = RestockingAction::INSPECTION;
#[ORM\Column(length: 180, nullable: true)]
private ?string $reason = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $notes = null;
#[ORM\OneToOne(mappedBy: 'salesReturnItem', targetEntity: ReturnDamageReport::class, cascade: ['persist', 'remove'])]
private ?ReturnDamageReport $damageReport = null;
public function getId(): ?int
{
return $this->id;
}
public function getSalesReturn(): ?SalesReturn
{
return $this->salesReturn;
}
public function setSalesReturn(?SalesReturn $salesReturn): self
{
$this->salesReturn = $salesReturn;
return $this;
}
public function getProductsSold(): ?ProductsSold
{
return $this->productsSold;
}
public function setProductsSold(ProductsSold $productsSold): self
{
$this->productsSold = $productsSold;
return $this;
}
public function getRequestedQuantity(): float
{
return (float) $this->requestedQuantity;
}
public function setRequestedQuantity(float $requestedQuantity): self
{
$this->requestedQuantity = (string) $requestedQuantity;
return $this;
}
public function getApprovedQuantity(): float
{
return (float) $this->approvedQuantity;
}
public function setApprovedQuantity(float $approvedQuantity): self
{
$this->approvedQuantity = (string) $approvedQuantity;
return $this;
}
public function getApprovedBaseQuantity(): float
{
return (float) $this->approvedBaseQuantity;
}
public function setApprovedBaseQuantity(float $approvedBaseQuantity): self
{
$this->approvedBaseQuantity = (string) $approvedBaseQuantity;
return $this;
}
public function getCondition(): ReturnItemCondition
{
return $this->condition;
}
public function setCondition(ReturnItemCondition $condition): self
{
$this->condition = $condition;
return $this;
}
public function getRestockingAction(): RestockingAction
{
return $this->restockingAction;
}
public function setRestockingAction(RestockingAction $restockingAction): self
{
$this->restockingAction = $restockingAction;
return $this;
}
public function getReason(): ?string
{
return $this->reason;
}
public function setReason(?string $reason): self
{
$this->reason = $reason;
return $this;
}
public function getNotes(): ?string
{
return $this->notes;
}
public function setNotes(?string $notes): self
{
$this->notes = $notes;
return $this;
}
public function getDamageReport(): ?ReturnDamageReport
{
return $this->damageReport;
}
public function setDamageReport(?ReturnDamageReport $damageReport): self
{
if ($damageReport === null && $this->damageReport !== null) {
$this->damageReport->setSalesReturnItem(null);
}
if ($damageReport !== null && $damageReport->getSalesReturnItem() !== $this) {
$damageReport->setSalesReturnItem($this);
}
$this->damageReport = $damageReport;
return $this;
}
public function getGoodQuantity(): float
{
return (float) $this->goodQuantity;
}
public function setGoodQuantity(float $goodQuantity): self
{
$this->goodQuantity = (string) $goodQuantity;
return $this;
}
public function getGoodBaseQuantity(): float
{
return (float) $this->goodBaseQuantity;
}
public function setGoodBaseQuantity(float $goodBaseQuantity): self
{
$this->goodBaseQuantity = (string) $goodBaseQuantity;
return $this;
}
public function getDamagedQuantity(): float
{
return (float) $this->damagedQuantity;
}
public function setDamagedQuantity(float $damagedQuantity): self
{
$this->damagedQuantity = (string) $damagedQuantity;
return $this;
}
public function getDamagedBaseQuantity(): float
{
return (float) $this->damagedBaseQuantity;
}
public function setDamagedBaseQuantity(float $damagedBaseQuantity): self
{
$this->damagedBaseQuantity = (string) $damagedBaseQuantity;
return $this;
}
public function isRestocked(): bool
{
return $this->restocked;
}
public function setRestocked(bool $restocked): self
{
$this->restocked = $restocked;
return $this;
}
public function getRestockedAt(): ?\DateTimeImmutable
{
return $this->restockedAt;
}
public function setRestockedAt(?\DateTimeImmutable $restockedAt): self
{
$this->restockedAt = $restockedAt;
return $this;
}
public function markAsRestocked(): self
{
$this->restocked = true;
$this->restockedAt = new \DateTimeImmutable('now');
return $this;
}
public function __toString(): string
{
$productName = $this->productsSold?->getProductName() ?? 'Unknown';
return sprintf('SalesReturnItem #%d (%s - Qty: %.2f)', $this->id ?? 0, $productName, $this->getApprovedQuantity());
}
}