<?php
namespace App\Entity;
use App\Repository\SupplierRepository;
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: SupplierRepository::class)]
#[ORM\HasLifecycleCallbacks]
class Supplier extends BaseEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 255)]
#[Assert\NotBlank(message: 'Firma adı boş bırakılamaz.')]
#[Assert\Length(min: 2, max: 255, minMessage: 'Firma adı en az 2 karakter olmalıdır.')]
private ?string $companyName = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $contactPerson = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Assert\Email(message: 'Geçerli bir e-posta adresi giriniz.')]
private ?string $email = null;
#[ORM\Column(type: 'string', length: 50, nullable: true)]
private ?string $phone = null;
#[ORM\Column(type: 'text', nullable: true)]
private ?string $address = null;
#[ORM\Column(type: 'string', length: 50, nullable: true)]
private ?string $taxNumber = null;
#[ORM\Column(type: 'string', length: 100, nullable: true)]
private ?string $taxOffice = null;
#[ORM\Column(type: 'boolean')]
private ?bool $isActive = true;
#[ORM\ManyToMany(targetEntity: Product::class, mappedBy: 'suppliers')]
private Collection $products;
#[ORM\OneToMany(mappedBy: 'supplier', targetEntity: PurchaseOrder::class)]
private Collection $purchaseOrders;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $logo = null;
#[ORM\Column(type: 'json', nullable: true)]
private ?array $contacts = [];
#[ORM\Column(type: 'boolean', options: ['default' => false])]
private ?bool $isInternal = false;
#[ORM\ManyToOne(targetEntity: Company::class)]
#[ORM\JoinColumn(nullable: true, onDelete: 'CASCADE')]
private ?Company $linkedCompany = null;
public function __construct()
{
$this->products = new ArrayCollection();
$this->purchaseOrders = new ArrayCollection();
}
public function __toString(): string
{
return $this->companyName ?? 'N/A';
}
public function getId(): ?int
{
return $this->id;
}
public function getCompanyName(): ?string
{
return $this->companyName;
}
public function setCompanyName(string $companyName): self
{
$this->companyName = $companyName;
return $this;
}
public function getContactPerson(): ?string
{
return $this->contactPerson;
}
public function setContactPerson(?string $contactPerson): self
{
$this->contactPerson = $contactPerson;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): self
{
$this->email = $email;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(?string $address): self
{
$this->address = $address;
return $this;
}
public function getTaxNumber(): ?string
{
return $this->taxNumber;
}
public function setTaxNumber(?string $taxNumber): self
{
$this->taxNumber = $taxNumber;
return $this;
}
public function getTaxOffice(): ?string
{
return $this->taxOffice;
}
public function setTaxOffice(?string $taxOffice): self
{
$this->taxOffice = $taxOffice;
return $this;
}
public function isActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
/**
* @return Collection<int, Product>
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(Product $product): self
{
if (!$this->products->contains($product)) {
$this->products[] = $product;
$product->addSupplier($this);
}
return $this;
}
public function removeProduct(Product $product): self
{
if ($this->products->removeElement($product)) {
$product->removeSupplier($this);
}
return $this;
}
public function getLogo(): ?string
{
return $this->logo;
}
public function setLogo(?string $logo): self
{
$this->logo = $logo;
return $this;
}
public function getContacts(): ?array
{
return $this->contacts;
}
public function setContacts(?array $contacts): self
{
$this->contacts = $contacts;
return $this;
}
/**
* @return Collection<int, PurchaseOrder>
*/
public function getPurchaseOrders(): Collection
{
return $this->purchaseOrders;
}
public function addPurchaseOrder(PurchaseOrder $purchaseOrder): self
{
if (!$this->purchaseOrders->contains($purchaseOrder)) {
$this->purchaseOrders[] = $purchaseOrder;
$purchaseOrder->setSupplier($this);
}
return $this;
}
public function removePurchaseOrder(PurchaseOrder $purchaseOrder): self
{
if ($this->purchaseOrders->removeElement($purchaseOrder)) {
// set the owning side to null (unless already changed)
if ($purchaseOrder->getSupplier() === $this) {
$purchaseOrder->setSupplier(null);
}
}
return $this;
}
public function isInternal(): ?bool
{
return $this->isInternal;
}
public function setIsInternal(bool $isInternal): self
{
$this->isInternal = $isInternal;
return $this;
}
public function getLinkedCompany(): ?Company
{
return $this->linkedCompany;
}
public function setLinkedCompany(?Company $linkedCompany): self
{
$this->linkedCompany = $linkedCompany;
return $this;
}
}