<?php
namespace App\Entity\Slave;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="eposm_s_client")
* @ORM\Entity(repositoryClass="App\Repository\Slave\ClientRepository")
*/
class Client
{
public function __toString()
{
if($this->getName() != null)
return $this->getName();
elseif($this->getNickname() != null)
return $this->getNickname();
else
return $this->getCode();
}
public function canDelete(){
if(sizeof($this->getTickets()) > 0) return false;
if($this->getWarehouse() != null && !$this->getWarehouse()->canDelete()) return false;
return true;
}
public function getPhoneByName($name)
{
foreach($this->getPhones() as $phone)
if($phone->getName() == $name && $phone->getNumber() != '' && $phone->getNumber() != '-' && $phone->getNumber() != '.' && $phone->getNumber() != '*' && $phone->getNumber() != '//' && $phone->getNumber() != 'non disp.')
return $phone->getNumber();
return '';
}
public function displayPhones()
{
$res = "";
foreach($this->getPhones() as $phone){
if($phone->getNumber() != '' && $phone->getNumber() != '-' && $phone->getNumber() != '.' && $phone->getNumber() != '*' && $phone->getNumber() != '//' && $phone->getNumber() != 'non disp.')
$res.= $phone->getName().': '.$phone->getNumber().'<br>';
}
return $res;
}
public function displayTermids($type)
{
$html = '';
switch($type){
case 'table':
$html = '<table class="table table_no_padding b_none m_b_none">';
foreach($this->getTermids() as $termid){
$html.= '<tr><td>'.$termid->getCode().'</td></tr>';
}
$html.= '</table>';
break;
case 'string':
$first = true;
foreach($this->getTermids() as $termid){
if($first) $first = false; else $html.= ', ';
$html.= $termid->getCode();
}
break;
default: break;
}
return $html;
}
/**
* @ORM\Column(name="id", type="bigint")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="code", type="string", length=191, nullable=true)
*/
protected $code;
/**
* @ORM\Column(name="name", type="string", length=191, nullable=true)
*/
protected $name;
/**
* @ORM\Column(name="nickname", type="string", length=191, nullable=true)
*/
protected $nickname;
/**
* @ORM\Column(name="referent", type="string", length=191, nullable=true)
*/
protected $referent;
/**
* @ORM\Column(name="fiscal_code", type="string", length=191, nullable=true)
*/
protected $fiscalCode;
/**
* @ORM\Column(name="vat", type="string", length=191, nullable=true)
*/
protected $vat;
/**
* @ORM\Column(name="sdi", type="string", length=191, nullable=true)
*/
protected $sdi;
/**
* @ORM\Column(name="address", type="string", length=191, nullable=true)
*/
protected $address;
/**
* @ORM\Column(name="locality", type="string", length=191, nullable=true)
*/
protected $locality;
/**
* @ORM\Column(name="zip", type="string", length=191, nullable=true)
*/
protected $zip;
/**
* @ORM\Column(name="id_city", type="bigint", nullable=true)
*/
protected $idCity;
/**
* @ORM\Column(name="id_province", type="bigint", nullable=true)
*/
protected $idProvince;
/**
* @ORM\Column(name="closures", type="text", nullable=true)
*/
protected $closures;
/**
* @ORM\Column(name="openings", type="text", nullable=true)
*/
protected $openings;
/**
* @ORM\Column(name="notes", type="text", nullable=true)
*/
protected $notes;
/**
* @ORM\Column(name="directory_path", type="string", length=191, nullable=true)
*/
protected $directoryPath;
// OneToOne
/**
* @ORM\OneToOne(targetEntity="App\Entity\Slave\Warehouse", mappedBy="client")
*/
private $warehouse;
//
// OneToMany
/**
* @ORM\OneToMany(targetEntity="App\Entity\Slave\Termid", mappedBy="client")
*/
private $termids;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Slave\Ticket", mappedBy="client")
*/
private $tickets;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Slave\ClientPhone", mappedBy="client")
*/
private $phones;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Slave\ClientFile", mappedBy="client")
*/
private $files;
public function __construct()
{
$this->termids = new ArrayCollection();
$this->tickets = new ArrayCollection();
$this->phones = new ArrayCollection();
$this->files = new ArrayCollection();
}
//
public function getId(): ?string
{
return $this->id;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(?string $code): static
{
$this->code = $code;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): static
{
$this->name = $name;
return $this;
}
public function getNickname(): ?string
{
return $this->nickname;
}
public function setNickname(?string $nickname): static
{
$this->nickname = $nickname;
return $this;
}
public function getReferent(): ?string
{
return $this->referent;
}
public function setReferent(?string $referent): static
{
$this->referent = $referent;
return $this;
}
public function getFiscalCode(): ?string
{
return $this->fiscalCode;
}
public function setFiscalCode(?string $fiscalCode): static
{
$this->fiscalCode = $fiscalCode;
return $this;
}
public function getVat(): ?string
{
return $this->vat;
}
public function setVat(?string $vat): static
{
$this->vat = $vat;
return $this;
}
public function getSdi(): ?string
{
return $this->sdi;
}
public function setSdi(?string $sdi): static
{
$this->sdi = $sdi;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(?string $address): static
{
$this->address = $address;
return $this;
}
public function getLocality(): ?string
{
return $this->locality;
}
public function setLocality(?string $locality): static
{
$this->locality = $locality;
return $this;
}
public function getZip(): ?string
{
return $this->zip;
}
public function setZip(?string $zip): static
{
$this->zip = $zip;
return $this;
}
public function getIdCity(): ?string
{
return $this->idCity;
}
public function setIdCity(?string $idCity): static
{
$this->idCity = $idCity;
return $this;
}
public function getIdProvince(): ?string
{
return $this->idProvince;
}
public function setIdProvince(?string $idProvince): static
{
$this->idProvince = $idProvince;
return $this;
}
public function getClosures(): ?string
{
return $this->closures;
}
public function setClosures(?string $closures): static
{
$this->closures = $closures;
return $this;
}
public function getOpenings(): ?string
{
return $this->openings;
}
public function setOpenings(?string $openings): static
{
$this->openings = $openings;
return $this;
}
public function getNotes(): ?string
{
return $this->notes;
}
public function setNotes(?string $notes): static
{
$this->notes = $notes;
return $this;
}
public function getWarehouse(): ?Warehouse
{
return $this->warehouse;
}
public function setWarehouse(?Warehouse $warehouse): static
{
// unset the owning side of the relation if necessary
if ($warehouse === null && $this->warehouse !== null) {
$this->warehouse->setClient(null);
}
// set the owning side of the relation if necessary
if ($warehouse !== null && $warehouse->getClient() !== $this) {
$warehouse->setClient($this);
}
$this->warehouse = $warehouse;
return $this;
}
/**
* @return Collection<int, Termid>
*/
public function getTermids(): Collection
{
return $this->termids;
}
public function addTermid(Termid $termid): static
{
if (!$this->termids->contains($termid)) {
$this->termids->add($termid);
$termid->setClient($this);
}
return $this;
}
public function removeTermid(Termid $termid): static
{
if ($this->termids->removeElement($termid)) {
// set the owning side to null (unless already changed)
if ($termid->getClient() === $this) {
$termid->setClient(null);
}
}
return $this;
}
/**
* @return Collection<int, Ticket>
*/
public function getTickets(): Collection
{
return $this->tickets;
}
public function addTicket(Ticket $ticket): static
{
if (!$this->tickets->contains($ticket)) {
$this->tickets->add($ticket);
$ticket->setClient($this);
}
return $this;
}
public function removeTicket(Ticket $ticket): static
{
if ($this->tickets->removeElement($ticket)) {
// set the owning side to null (unless already changed)
if ($ticket->getClient() === $this) {
$ticket->setClient(null);
}
}
return $this;
}
/**
* @return Collection<int, ClientPhone>
*/
public function getPhones(): Collection
{
return $this->phones;
}
public function addPhone(ClientPhone $phone): static
{
if (!$this->phones->contains($phone)) {
$this->phones->add($phone);
$phone->setClient($this);
}
return $this;
}
public function removePhone(ClientPhone $phone): static
{
if ($this->phones->removeElement($phone)) {
// set the owning side to null (unless already changed)
if ($phone->getClient() === $this) {
$phone->setClient(null);
}
}
return $this;
}
public function getDirectoryPath(): ?string
{
return $this->directoryPath;
}
public function setDirectoryPath(?string $directoryPath): static
{
$this->directoryPath = $directoryPath;
return $this;
}
/**
* @return Collection<int, ClientFile>
*/
public function getFiles(): Collection
{
return $this->files;
}
public function addFile(ClientFile $file): static
{
if (!$this->files->contains($file)) {
$this->files->add($file);
$file->setClient($this);
}
return $this;
}
public function removeFile(ClientFile $file): static
{
if ($this->files->removeElement($file)) {
// set the owning side to null (unless already changed)
if ($file->getClient() === $this) {
$file->setClient(null);
}
}
return $this;
}
}