<?php
namespace App\Entity;
use App\Enum\ProductTypeEnum;
use App\Repository\ProductRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: ProductRepository::class)]
#[ORM\HasLifecycleCallbacks]
class Product extends BaseEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 255)]
private ?string $name = null;
#[ORM\Column(type: 'text', nullable: true)]
private ?string $description = null;
#[ORM\Column(type: 'string', length: 255)]
private ?string $code = null;
#[ORM\ManyToOne(targetEntity: MeasurementUnits::class)]
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
private ?MeasurementUnits $measurementUnit = null;
#[ORM\ManyToOne(targetEntity: Measurements::class, inversedBy: 'products')]
#[Assert\NotNull(message: 'Lutfen bir olcu secin.')]
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
private ?Measurements $measurement = null;
#[ORM\OneToMany(mappedBy: 'product', targetEntity: Stock::class)]
private Collection $stocks;
#[ORM\Column(type: 'decimal', precision: 10, scale: 2, nullable: true)]
private ?string $purchasePrice = null;
#[ORM\Column(type: 'decimal', precision: 10, scale: 2, nullable: true)]
private ?string $warehousePrice = null;
#[ORM\Column(type: 'decimal', precision: 10, scale: 2)]
private ?string $salePrice = '0.00';
#[ORM\OneToMany(mappedBy: 'product', targetEntity: StockInfo::class)]
private Collection $stockInfos;
#[ORM\OneToMany(mappedBy: 'product', targetEntity: ProductsSold::class)]
private Collection $productsSolds;
#[ORM\OneToMany(mappedBy: 'product', targetEntity: InvoiceItem::class)]
private Collection $invoiceItems;
#[ORM\OneToMany(mappedBy: 'product', targetEntity: StockTransferProducts::class)]
private Collection $stockTransferProducts;
#[ORM\OneToMany(mappedBy: 'product', targetEntity: BuyInTurkey::class)]
private Collection $buyInTurkeys;
#[ORM\OneToMany(mappedBy: 'Product', targetEntity: StockTransferProducts::class)]
private Collection $containerProducts;
#[ORM\OneToMany(mappedBy: 'product', targetEntity: NewTransferProducts::class)]
private Collection $newTransferProducts;
#[ORM\OneToMany(mappedBy: 'product', targetEntity: StockTakeProducts::class)]
private Collection $stockTakeProducts;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $image = null;
#[ORM\OneToMany(mappedBy: 'productId', targetEntity: StockTransaction::class)]
private Collection $stockTransactions;
#[ORM\Column(type: 'string', length: 255, enumType: ProductTypeEnum::class)]
private ProductTypeEnum $productTypeEnum = ProductTypeEnum::SINGLE_ITEM;
#[ORM\Column(type: 'boolean', options: ['default' => true])]
private ?bool $isConvertible = true;
public function __construct()
{
$this->stocks = new ArrayCollection();
$this->stockInfos = new ArrayCollection();
$this->productsSolds = new ArrayCollection();
$this->invoiceItems = new ArrayCollection();
$this->stockTransferProducts = new ArrayCollection();
$this->buyInTurkeys = new ArrayCollection();
$this->containerProducts = new ArrayCollection();
$this->newTransferProducts = new ArrayCollection();
$this->stockTakeProducts = new ArrayCollection();
$this->stockTransactions = new ArrayCollection();
}
public function __toString(): string
{
return $this->getName() . ' - ' . $this->getCode() . ' - ' . ($this->getMeasurement()?->getMeasurement() ?? 'Birim Yok');
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): void
{
$this->description = $description;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(?string $code): void
{
$this->code = $code;
}
public function getMeasurementUnit(): ?MeasurementUnits
{
return $this->measurementUnit;
}
public function setMeasurementUnit(?MeasurementUnits $measurementUnit): void
{
$this->measurementUnit = $measurementUnit;
}
public function getMeasurement(): ?Measurements
{
return $this->measurement;
}
public function setMeasurement(?Measurements $measurement): void
{
$this->measurement = $measurement;
}
public function getStocks(): Collection
{
return $this->stocks;
}
public function setStocks(Collection $stocks): void
{
$this->stocks = $stocks;
}
public function getPurchasePrice(): ?string
{
return $this->purchasePrice;
}
public function setPurchasePrice(?string $purchasePrice): void
{
$this->purchasePrice = $purchasePrice;
}
public function getWarehousePrice(): ?string
{
return $this->warehousePrice;
}
public function setWarehousePrice(?string $warehousePrice): void
{
$this->warehousePrice = $warehousePrice;
}
public function getSalePrice(): ?string
{
return $this->salePrice;
}
public function setSalePrice(?string $salePrice): void
{
$this->salePrice = $salePrice ?? '0.00';
}
public function getStockInfos(): Collection
{
return $this->stockInfos;
}
public function setStockInfos(Collection $stockInfos): void
{
$this->stockInfos = $stockInfos;
}
public function getProductsSolds(): Collection
{
return $this->productsSolds;
}
public function setProductsSolds(Collection $productsSolds): void
{
$this->productsSolds = $productsSolds;
}
public function getInvoiceItems(): Collection
{
return $this->invoiceItems;
}
public function setInvoiceItems(Collection $invoiceItems): void
{
$this->invoiceItems = $invoiceItems;
}
public function getStockTransferProducts(): Collection
{
return $this->stockTransferProducts;
}
public function setStockTransferProducts(Collection $stockTransferProducts): void
{
$this->stockTransferProducts = $stockTransferProducts;
}
public function getBuyInTurkeys(): Collection
{
return $this->buyInTurkeys;
}
public function setBuyInTurkeys(Collection $buyInTurkeys): void
{
$this->buyInTurkeys = $buyInTurkeys;
}
public function getContainerProducts(): Collection
{
return $this->containerProducts;
}
public function setContainerProducts(Collection $containerProducts): void
{
$this->containerProducts = $containerProducts;
}
public function getNewTransferProducts(): Collection
{
return $this->newTransferProducts;
}
public function setNewTransferProducts(Collection $newTransferProducts): void
{
$this->newTransferProducts = $newTransferProducts;
}
public function getStockTakeProducts(): Collection
{
return $this->stockTakeProducts;
}
public function setStockTakeProducts(Collection $stockTakeProducts): void
{
$this->stockTakeProducts = $stockTakeProducts;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): void
{
$this->image = $image;
}
public function getStockTransactions(): Collection
{
return $this->stockTransactions;
}
public function setStockTransactions(Collection $stockTransactions): void
{
$this->stockTransactions = $stockTransactions;
}
public function getProductTypeEnum(): ProductTypeEnum
{
return $this->productTypeEnum;
}
public function setProductTypeEnum(?ProductTypeEnum $productTypeEnum): self
{
$this->productTypeEnum = $productTypeEnum ?? ProductTypeEnum::SINGLE_ITEM;
return $this;
}
public function isConvertible(): bool
{
return $this->isConvertible !== null ? (bool)$this->isConvertible : true;
}
public function setIsConvertible(bool $isConvertible): self
{
$this->isConvertible = $isConvertible;
return $this;
}
}