<?php
namespace App\Entity\Master;
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_m_supplier")
* @ORM\Entity(repositoryClass="App\Repository\Master\SupplierRepository")
*/
class Supplier
{
public function __toString(){
return $this->name;
}
public function canDelete(){
if(sizeof($this->companies) > 0) return false;
return true;
}
public function mainAddress(){
foreach($this->getAddresses() as $address){
if($address->isMain())
return $address;
}
}
public function displayCompanies(){
$result = '';
if(sizeof($this->companies) > 0){
$first = true;
foreach($this->companies as $jtcs){
if($first) $first = false; else $result.= '<br>';
$result.= $jtcs->getCompany()->getName();
}
}
else{
$result = '---';
}
return $result;
}
public function displayOperations(){
$result = '';
if(sizeof($this->operations) > 0){
$result = '<table class="table table_padding_01 b_none m_b_none">';
foreach($this->operations as $operation){
$result.= '<tr><td class="td_w_200p">'.$operation->getName().'</td><td>'.$operation->getSlug().'</td></tr>';
}
$result.= '</table>';
}
else{
$result = '---';
}
return $result;
}
/**
* @ORM\Column(name="id", type="bigint")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="nickname", type="string", length=191)
*/
protected $nickname;
/**
* @ORM\Column(name="name", type="string", length=191)
*/
protected $name;
/**
* @ORM\Column(name="phone", type="string", length=191, nullable=true)
*/
protected $phone;
// OneToMany
/**
* @ORM\OneToMany(targetEntity="App\Entity\Master\JoinTableCompanySupplier", mappedBy="supplier")
*/
private $companies;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Master\SupplierOperation", mappedBy="supplier")
*/
private $operations;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Master\Address", mappedBy="supplier")
*/
private $addresses;
//
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Master\CompanyMailer", inversedBy="suppliers")
* @ORM\JoinTable(name="eposm_m_join_table_company_mailer_supplier")
*/
private $mailers;
public function __construct()
{
$this->companies = new ArrayCollection();
$this->operations = new ArrayCollection();
$this->addresses = new ArrayCollection();
$this->mailers = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function getNickname(): ?string
{
return $this->nickname;
}
public function setNickname(string $nickname): static
{
$this->nickname = $nickname;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): static
{
$this->phone = $phone;
return $this;
}
/**
* @return Collection<int, JoinTableCompanySupplier>
*/
public function getCompanies(): Collection
{
return $this->companies;
}
public function addCompany(JoinTableCompanySupplier $company): static
{
if (!$this->companies->contains($company)) {
$this->companies->add($company);
$company->setSupplier($this);
}
return $this;
}
public function removeCompany(JoinTableCompanySupplier $company): static
{
if ($this->companies->removeElement($company)) {
// set the owning side to null (unless already changed)
if ($company->getSupplier() === $this) {
$company->setSupplier(null);
}
}
return $this;
}
/**
* @return Collection<int, SupplierOperation>
*/
public function getOperations(): Collection
{
return $this->operations;
}
public function addOperation(SupplierOperation $operation): static
{
if (!$this->operations->contains($operation)) {
$this->operations->add($operation);
$operation->setSupplier($this);
}
return $this;
}
public function removeOperation(SupplierOperation $operation): static
{
if ($this->operations->removeElement($operation)) {
// set the owning side to null (unless already changed)
if ($operation->getSupplier() === $this) {
$operation->setSupplier(null);
}
}
return $this;
}
/**
* @return Collection<int, Address>
*/
public function getAddresses(): Collection
{
return $this->addresses;
}
public function addAddress(Address $address): static
{
if (!$this->addresses->contains($address)) {
$this->addresses->add($address);
$address->setSupplier($this);
}
return $this;
}
public function removeAddress(Address $address): static
{
if ($this->addresses->removeElement($address)) {
// set the owning side to null (unless already changed)
if ($address->getSupplier() === $this) {
$address->setSupplier(null);
}
}
return $this;
}
/**
* @return Collection<int, CompanyMailer>
*/
public function getMailers(): Collection
{
return $this->mailers;
}
public function addMailer(CompanyMailer $mailer): static
{
if (!$this->mailers->contains($mailer)) {
$this->mailers->add($mailer);
}
return $this;
}
public function removeMailer(CompanyMailer $mailer): static
{
$this->mailers->removeElement($mailer);
return $this;
}
}