<?php
namespace App\Daikin\BaseBundle\Entity;
use App\Daikin\BaseBundle\Entity\Survey\ProtocolGroup;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use EHC\HTMLIdableBundle\Interfaces\HTMLIdableInterface;
/**
* @ORM\Entity(repositoryClass="App\Daikin\BaseBundle\Repository\CompanyRepository")
* @ORM\Table(name="company")
* @UniqueEntity("name")
*/
class Company extends AbstractDeleteableEntity implements HTMLIdableInterface
{
/**
* aus 00 => + oder + an Anfang wenn nicht vorhanden
* @var bool
*/
protected $addMissingPlusPhone = true;
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*
* @var integer $id
*/
protected $id;
/**
* @ORM\Column(type="string", name="name", unique=true)
*
* @var string $name
*/
protected $name;
/**
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="integer", name="created_at")
*
* @var integer $createdAt
*/
protected $createdAt;
/**
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="integer", name="updated_at")
*
* @var integer $updatedAt
*/
protected $updatedAt;
/**
* @ORM\Column(type="string", name="street")
*
* @var string $street
*/
protected $street;
/**
* @ORM\Column(length=6)
*
* @var string $zipcode
*/
protected $zipcode;
/**
* @ORM\Column(type="string", name="city")
*
* @var string $city
*/
protected $city;
/**
* @ORM\Column(type="string", name="telephone", nullable=true)
*
* @var string $telephone
*/
protected $telephone;
/**
* @ORM\OneToMany(targetEntity="User", mappedBy="company")
*
* @var ArrayCollection $users
*/
protected $users;
/**
* @ORM\OneToMany(targetEntity="Objects", mappedBy="company")
*/
protected $objects;
/**
* @ORM\Column(length=10, nullable=true, unique=true)
*/
protected $sapnumber;
/**
* @var ArrayCollection|ProtocolGroup[]
* @ORM\ManyToMany(targetEntity="App\Daikin\BaseBundle\Entity\Survey\ProtocolGroup", mappedBy="companies")
*/
protected $protocol_groups;
/**
* @ORM\OneToOne(targetEntity="App\Daikin\BaseBundle\Entity\CompanyCertificate", mappedBy="company", cascade={"persist"}, orphanRemoval=true)
*/
protected $certificate;
/**
* Datum der Bestätigung von "Bedingungen der Bestellung von R410A Kältemittel"
*
* @ORM\Column(name="refShopAcceptedConditions", type="datetime", nullable=true)
*/
protected $refShopAcceptedConditions;
/**
* @var User
* @ORM\ManyToOne(targetEntity="App\Daikin\BaseBundle\Entity\User")
* @ORM\JoinColumn(name="userAcceptedConditions_id", onDelete="SET NULL")
*/
private $userAcceptedConditions;
/**
* @var DateTime
*
* @ORM\Column(type="datetime", nullable=true)
*/
protected $converted_from_rotex;
/**
* @var int
*
* @ORM\Column(type="integer", nullable=true)
*/
protected $converted_from_rotex_company_id;
/**
* Conructor for class
*/
public function __construct()
{
parent::__construct();
$this->users = new ArrayCollection();
$this->objects = new ArrayCollection();
$this->protocol_groups = new ArrayCollection;
$this->createdAt = time();
$this->updatedAt = time();
}
public function __toString()
{
return $this->getName();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
public function getHTMLId()
{
return 'company-'.$this->id;
}
/**
* Set name
*
* @param string $name
* @return Company
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set createdAt
*
* @param int $createdAt
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
}
/**
* Get createdAt
*
* @return int
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set updatedAt
*
* @param integer $updatedAt
* @return Company
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* Get updatedAt
*
* @return integer
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* Set street
*
* @param string $street
* @return Company
*/
public function setStreet($street)
{
$this->street = $street;
return $this;
}
/**
* Get street
*
* @return string
*/
public function getStreet()
{
return $this->street;
}
/**
* Set zipcode
*
* @param string $zipcode
* @return Company
*/
public function setZipcode($zipcode)
{
$this->zipcode = $zipcode;
return $this;
}
/**
* Get zipcode
*
* @return string
*/
public function getZipcode()
{
return $this->zipcode ? sprintf('%0'.mb_strlen($this->zipcode).'d', $this->zipcode) : null;
}
/**
* Set city
*
* @param string $city
* @return Company
*/
public function setCity($city)
{
$this->city = $city;
return $this;
}
/**
* Get city
*
* @return string
*/
public function getCity()
{
return $this->city;
}
/**
* @return bool
*/
public function isAddMissingPlusPhone()
{
return $this->addMissingPlusPhone;
}
/**
* @param bool $addMissingPlusPhone
* @return Company
*/
public function setAddMissingPlusPhone($addMissingPlusPhone)
{
$this->addMissingPlusPhone = $addMissingPlusPhone;
return $this;
}
/**
* Set telephone
*
* @param string $telephone
* @return Company
*/
public function setTelephone($telephone)
{
if ($this->isAddMissingPlusPhone()) {
$telephone = preg_replace( '#^00#', '+', $telephone );
$this->telephone = ( strpos( $telephone, '+' ) === 0 ) ? $telephone : '+'.$telephone;
}else{
$this->telephone = $telephone;
}
return $this;
}
/**
* Get telephone
*
* @return string
*/
public function getTelephone()
{
return $this->telephone;
}
/**
* Get users
*
* @return ArrayCollection|User[]
*/
public function getUsers()
{
return $this->users;
}
/**
* Get objects
*
* @return ArrayCollection|Objects[]
*/
public function getObjects()
{
return $this->objects;
}
/**
* set the SAP number
*
* @param string $sapnumber
* @return Company
*/
public function setSapnumber( $sapnumber = null )
{
$this->sapnumber = $sapnumber;
return $this;
}
/**
* get the SAP number
*
* @return string
*/
public function getSapnumber()
{
return $this->sapnumber;
}
/**
* @return ProtocolGroup[]|ArrayCollection
*/
public function getProcolGroups()
{
return $this->protocol_groups;
}
/**
* @return CompanyCertificate
*/
public function getCertificate()
{
return $this->certificate;
}
/**
* @param mixed $certificate
* @return Company
*/
public function setCertificate($certificate)
{
$this->certificate = $certificate;
return $this;
}
/**
* @return DateTime
*/
public function getRefShopAcceptedConditions()
{
return $this->refShopAcceptedConditions;
}
/**
* @return bool
*/
public function hasRefShopAcceptedConditions()
{
return $this->refShopAcceptedConditions instanceof DateTime;
}
/**
* @param mixed $refShopAcceptedConditions
* @return Company
*/
public function setRefShopAcceptedConditions(DateTime $refShopAcceptedConditions)
{
$this->refShopAcceptedConditions = $refShopAcceptedConditions;
return $this;
}
/**
* @return Company
*/
public function initRefShopAcceptedConditions()
{
if (!$this->refShopAcceptedConditions) {
$this->refShopAcceptedConditions = new DateTime();
}
return $this;
}
/**
* @return User
*/
public function getUserAcceptedConditions()
{
return $this->userAcceptedConditions;
}
/**
* @param User $userAcceptedConditions
* @return Company
*/
public function setUserAcceptedConditions($userAcceptedConditions)
{
$this->userAcceptedConditions = $userAcceptedConditions;
return $this;
}
/**
* @return ProtocolGroup[]|ArrayCollection
*/
public function getProtocolGroups()
{
return $this->protocol_groups;
}
/**
* @param ProtocolGroup[]|ArrayCollection $protocol_groups
* @return Company
*/
public function setProtocolGroups($protocol_groups)
{
$this->protocol_groups = $protocol_groups;
return $this;
}
/**
* @return DateTime
*/
public function getConvertedFromRotex()
{
return $this->converted_from_rotex;
}
/**
* @param DateTime $converted_from_rotex
* @return Company
*/
public function setConvertedFromRotex(DateTime $converted_from_rotex)
{
$this->converted_from_rotex = $converted_from_rotex;
return $this;
}
/**
* @return int
*/
public function getConvertedFromRotexCompanyId(): int
{
return $this->converted_from_rotex_company_id;
}
/**
* @param int $converted_from_rotex_company_id
* @return Company
*/
public function setConvertedFromRotexCompanyId(int $converted_from_rotex_company_id): Company
{
$this->converted_from_rotex_company_id = $converted_from_rotex_company_id;
return $this;
}
}