<?php
namespace App\Entity\Produit;
use App\Entity\Order\OrderLineGarantie;
use App\Repository\GarantieRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Produit\Produit;
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
#[ORM\Entity(repositoryClass: GarantieRepository::class)]
class Garantie implements TranslatableInterface
{
use TranslatableTrait;
#[Assert\Valid]
protected $translations;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\ManyToMany(targetEntity: Produit::class, mappedBy: 'garantie')]
private $produits;
#[ORM\Column(type: 'decimal', precision: 10, scale: 2, nullable:true)]
private $priceHt;
#[ORM\Column(type: 'decimal', precision: 10, scale: 2, nullable:true)]
private $priceTtc;
#[ORM\Column(type: 'decimal', precision: 10, scale: 2, nullable:true)]
private $taxRate;
#[ORM\OneToMany(mappedBy: 'garantie', targetEntity: OrderLineGarantie::class)]
private Collection $orderLineGaranties;
public function __construct()
{
$this->produits = new ArrayCollection();
$this->orderLineGaranties = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getPrice(): ?string
{
return $this->priceTtc;
}
public function getPriceHt()
{
return $this->priceHt;
}
public function setPriceHt($priceHt): self
{
$this->priceHt = $priceHt;
return $this;
}
public function getPriceTtc()
{
return $this->priceTtc;
}
public function setPriceTtc($priceTtc): self
{
$this->priceTtc = $priceTtc;
return $this;
}
public function getTaxRate()
{
return $this->taxRate;
}
public function setTaxRate($taxRate): self
{
$this->taxRate = $taxRate;
return $this;
}
/**
* @return Collection<int, Produit>
*/
public function getProduits(): Collection
{
return $this->produits;
}
public function addProduit(Produit $produit): self
{
if (!$this->produits->contains($produit)) {
$this->produits[] = $produit;
$produit->addGarantie($this);
}
return $this;
}
public function removeProduit(Produit $produit): self
{
if ($this->produits->removeElement($produit)) {
$produit->removeGarantie($this);
}
return $this;
}
public function getName(): ?string
{
if($this->translate()->getName()) {
return $this->translate()->getName();
}
return '';
}
/**
* @return Collection<int, OrderLineGarantie>
*/
public function getOrderLineGaranties(): Collection
{
return $this->orderLineGaranties;
}
public function addOrderLineGaranty(OrderLineGarantie $orderLineGaranty): static
{
if (!$this->orderLineGaranties->contains($orderLineGaranty)) {
$this->orderLineGaranties->add($orderLineGaranty);
$orderLineGaranty->setGarantie($this);
}
return $this;
}
public function removeOrderLineGaranty(OrderLineGarantie $orderLineGaranty): static
{
if ($this->orderLineGaranties->removeElement($orderLineGaranty)) {
// set the owning side to null (unless already changed)
if ($orderLineGaranty->getGarantie() === $this) {
$orderLineGaranty->setGarantie(null);
}
}
return $this;
}
public function __toString(){
return $this->translate()->getName();
}
}