<?php
namespace App\Entity;
use App\Model\Currency;
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="App\Repository\SupplierRepository"
* )
* @ORM\Table(
* name="supplier",
* options={"collate"="utf8_swedish_ci"},
* uniqueConstraints={
* @ORM\UniqueConstraint(
* name="supplier_label",
* columns={"label"}
* )
* }
* )
* @ORM\HasLifecycleCallbacks
*/
class Supplier implements EntityInterface, AddressInterface
{
use AddressTrait;
use TermsOfDeliveryTrait;
/**
* @ORM\Id
* @ORM\Column(
* type="integer"
* )
* @ORM\GeneratedValue(
* strategy="AUTO"
* )
*
* @var int|null
*/
protected ?int $id = null;
/**
* @ORM\Column(
* type="boolean"
* )
*
* @var bool
*/
protected bool $active = true;
/**
* @ORM\Column(
* type="string",
* length=3
* )
* @Assert\NotNull
* @Assert\Choice(
* callback={"\App\Model\Currency", "getCodeChoices"}
* )
*
* @var string
*/
protected string $currency = Currency::DEFAULT_CURRENCY;
/**
* @ORM\Column(
* type="boolean"
* )
*
* @var bool
*/
protected bool $grossMarginPurchasesZero = false;
/**
* @ORM\Column(
* type="boolean"
* )
*
* @var bool
*/
protected bool $inventoryAddress = false;
/**
* @ORM\Column(
* type="boolean"
* )
*
* @var bool
*/
protected bool $inventoryTransactions = false;
/**
* @ORM\Column(
* type="string",
* length=20,
* nullable=true
* )
*
* @var string|null
*/
protected ?string $label = null;
/**
* @ORM\Column(
* type="string",
* length=500
* )
*
* @var string
*/
protected string $name;
/**
* @ORM\OneToMany(
* targetEntity="Product",
* mappedBy="supplier",
* cascade={"persist"}
* )
* @orm\OrderBy({"code" = "ASC"})
*
* @var Collection<Product>
*/
protected Collection $products;
/**
* @ORM\OneToMany(
* targetEntity="PurchaseOrder",
* mappedBy="supplier",
* cascade={"persist"}
* )
*
* @var Collection<PurchaseOrder>
*/
protected Collection $purchaseOrders;
/**
* @ORM\OneToMany(
* targetEntity="SalesItem",
* mappedBy="supplier",
* cascade={"persist","remove"}
* )
*
* @var Collection<SalesItem>
*/
protected Collection $salesItems;
/**
* @ORM\ManyToMany(
* targetEntity="TermsOfPaymentRow",
* cascade={"persist","remove"},
* orphanRemoval=true
* )
* @ORM\JoinTable(
* name="supplier_terms_of_payment_row",
* joinColumns={
* @ORM\JoinColumn(
* name="supplier_id",
* referencedColumnName="id",
* onDelete="cascade"
* )
* },
* inverseJoinColumns={
* @ORM\JoinColumn(
* name="terms_of_payment_row_id",
* referencedColumnName="id",
* unique=true,
* onDelete="cascade"
* )
* }
* )
*
* @Assert\Valid
*
* @var Collection<TermsOfPaymentRow>
*/
protected Collection $termsOfPaymentRows;
/**
* @param string $name
*/
public function __construct(string $name)
{
$this->name = $name;
$this->products = new ArrayCollection();
$this->purchaseOrders = new ArrayCollection();
$this->salesItems = new ArrayCollection();
$this->termsOfPaymentRows = new ArrayCollection();
}
/**
* @return string
*/
public function __toString(): string
{
return $this->getName();
}
/**
* @param TermsOfPaymentRow $row
*/
public function addTermsOfPaymentRow(TermsOfPaymentRow $row): void
{
$this->termsOfPaymentRows->add($row);
}
/**
* @return string
*/
public function getCurrency(): string
{
return $this->currency;
}
/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @return null|string
*/
public function getLabel(): ?string
{
return $this->label;
}
/**
* @return Collection<PurchaseOrder>
*/
public function getPurchaseOrders(): Collection
{
return $this->purchaseOrders;
}
/**
* @return Collection<SalesItem>
*/
public function getSalesItems(): Collection
{
return $this->salesItems;
}
/**
* @return Collection<TermsOfPaymentRow>
*/
public function getTermsOfPaymentRows(): Collection
{
return $this->termsOfPaymentRows;
}
/**
* @return bool
*/
public function isActive(): bool
{
return $this->active;
}
/**
* @return bool
*/
public function isGrossMarginPurchasesZero(): bool
{
return $this->grossMarginPurchasesZero;
}
/**
* @return bool
*/
public function isInventoryAddress(): bool
{
return $this->inventoryAddress;
}
/**
* @return bool
*/
public function isInventoryTransactions(): bool
{
return $this->inventoryTransactions;
}
/**
* @param TermsOfPaymentRow $row
*/
public function removeTermsOfPaymentRow(TermsOfPaymentRow $row): void
{
$this->termsOfPaymentRows?->removeElement($row);
}
/**
* @param bool $active
*/
public function setActive(bool $active): void
{
$this->active = $active;
}
/**
* @param string $currency
*/
public function setCurrency(string $currency): void
{
$this->currency = $currency;
}
/**
* @param bool $grossMarginPurchasesZero
*/
public function setGrossMarginPurchasesZero(bool $grossMarginPurchasesZero): void
{
$this->grossMarginPurchasesZero = $grossMarginPurchasesZero;
}
/**
* @param bool $inventoryAddress
*/
public function setInventoryAddress(bool $inventoryAddress): void
{
$this->inventoryAddress = $inventoryAddress;
}
/**
* @param bool $inventoryTransactions
*/
public function setInventoryTransactions(bool $inventoryTransactions): void
{
$this->inventoryTransactions = $inventoryTransactions;
}
/**
* @param string|null $label
*/
public function setLabel(?string $label): void
{
$this->label = $label;
}
}