<?php
namespace App\Entity;
use App\Repository\DistributorRepository;
use App\Traits\DateTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use JMS\Serializer\Annotation\Expose;
use JMS\Serializer\Annotation\Groups;
use JMS\Serializer\Annotation\SerializedName;
/**
* @ORM\Entity(repositoryClass=DistributorRepository::class)
*
* @Serializer\ExclusionPolicy("ALL")
*/
class Distributor
{
use DateTrait;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*
* @Expose
* @Groups({"distributor", "export_distributor_datatable"})
*/
private ?int $id = NULL;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*
* @Expose
* @Groups({"distributor", "export_distributor_datatable", "export_purchase_declaration_datatable"})
*/
private ?string $company = NULL;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*
* @Expose
* @Groups({"distributor", "export_commercial_installer_datatable", "export_distributor_datatable", "export_installer_datatable"})
*/
private ?string $postcode = NULL;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*
* @Expose
* @Groups({"distributor", "export_commercial_installer_datatable", "export_distributor_datatable", "export_installer_datatable"})
*/
private ?string $city = NULL;
/**
* @ORM\Column(type="string", length=80, nullable=true)
*
* @Expose
* @Groups({"distributor", "export_distributor_datatable"})
*/
private ?string $internalCode = NULL;
/**
* @ORM\Column(type="boolean", options={"default" : true}, nullable=true)
*
* @Expose
* @Groups({"distributor", "export_distributor_datatable"})
*/
private ?bool $enabled = TRUE;
/**
* @ORM\ManyToMany(targetEntity=User::class, mappedBy="distributors")
*/
private Collection $users;
/**
* @ORM\OneToMany(targetEntity=Purchase::class, mappedBy="distributor")
*/
private Collection $purchases;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $address1 = NULL;
public function __construct()
{
$this->users = new ArrayCollection();
$this->purchases = new ArrayCollection();
}
/**
* @Serializer\VirtualProperty()
* @SerializedName("codeDep")
* @Expose
* @Groups({"export_installer_datatable", "export_commercial_installer_datatable"})
*
* @return false|string|null
*/
public function getCodeDep()
{
return $this->getPostcode() !== NULL ? substr($this->getPostcode(), 0, 2) : NULL;
}
public function getPostcode(): ?string
{
return $this->postcode;
}
public function setPostcode(?string $postcode): self
{
$this->postcode = $postcode;
return $this;
}
public function getId(): ?int
{
return $this->id;
}
public function getCompany(): ?string
{
return $this->company;
}
public function setCompany(?string $company): self
{
$this->company = $company;
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(?string $city): self
{
$this->city = $city;
return $this;
}
public function getInternalCode(): ?string
{
return $this->internalCode;
}
public function setInternalCode(?string $internalCode): self
{
$this->internalCode = $internalCode;
return $this;
}
public function getEnabled(): ?bool
{
return $this->enabled;
}
public function setEnabled(?bool $enabled): self
{
$this->enabled = $enabled;
return $this;
}
/**
* @return Collection|User[]
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(User $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
$user->addDistributor($this);
}
return $this;
}
public function removeUser(User $user): self
{
if ($this->users->removeElement($user)) {
$user->removeDistributor($this);
}
return $this;
}
/**
* @return Collection|Purchase[]
*/
public function getPurchases(): Collection
{
return $this->purchases;
}
public function addPurchase(Purchase $purchase): self
{
if (!$this->purchases->contains($purchase)) {
$this->purchases[] = $purchase;
$purchase->setDistributor($this);
}
return $this;
}
public function removePurchase(Purchase $purchase): self
{
if ($this->purchases->removeElement($purchase)) {
// set the owning side to null (unless already changed)
if ($purchase->getDistributor() === $this) {
$purchase->setDistributor(NULL);
}
}
return $this;
}
public function getAddress1(): ?string
{
return $this->address1;
}
public function setAddress1(?string $address1): self
{
$this->address1 = $address1;
return $this;
}
}