<?php
namespace Roothirsch\CoreBundle\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Metadata\Get;
use App\State\CompanyStateProcessor;
use Dkd\Populate\PopulateTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Roothirsch\CoreBundle\API\Filter\InArrayFilter;
use Roothirsch\CoreBundle\API\Filter\OrSearchFilter;
use Roothirsch\CoreBundle\Behaviors\Attributable\AttributableInterface;
use Roothirsch\CoreBundle\Behaviors\Attributable\Attribute\AttributeInterface;
use Roothirsch\CoreBundle\Behaviors\Attributable\AttributeValue\AttributeValueAwareInterface;
use Roothirsch\CoreBundle\Behaviors\Attributable\AttributeValue\AttributeValueInterface;
use Roothirsch\CoreBundle\Behaviors\Attributable\MappedSuperclass\AbstractAttributable;
use Roothirsch\CoreBundle\Entity\Company\CompanyAttributeValue;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="Roothirsch\CoreBundle\Repository\CompanyRepository")
* @ORM\Table(name="company")
* @ApiFilter(OrSearchFilter::class, properties={
* "name": "partial",
* "address.city": "partial",
* })
* @ApiFilter(InArrayFilter::class, properties={"groups"})
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\DiscriminatorMap({"company"= "App\Entity\Company", "core_company"= "Roothirsch\CoreBundle\Entity\Company"})
*/
class Company extends AbstractAttributable
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"list", "read", "company_read", "company_simple"})
*/
protected $id;
/**
* @var string
* @ORM\Column(type="string")
* @Assert\NotBlank()
* @Groups({"list", "read", "company_write", "company_read", "company_simple"})
*/
protected $name;
/**
* @var string
* @ORM\Column(type="string", nullable=true)
* @Groups({"list", "read", "company_write", "company_read", "company_simple"})
*/
protected $taxId;
/**
* @var string
* @ORM\Column(type="string")
* @Groups({"list", "read", "company_write", "company_read", "company_simple"})
*/
protected $currency = 'eur';
/**
* @ORM\Column(type="string")
* @Groups({"list", "read", "company_write", "company_read", "company_simple"})
*/
protected $language = 'de_CH';
/**
* @ORM\Column(type="boolean", options={"default"=false})
* @Groups({"read", "company_write", "company_read", "company_simple"})
*/
protected $verified = true;
/**
* @ORM\Column(type="boolean", options={"default"=false})
* @Groups({"read", "company_write", "company_read", "company_simple"})
*/
protected $blocked = false;
/**
* @ORM\Column(type="integer", options={"default"=0}, nullable=true)
* @Groups({"read", "company_write", "company_read", "company_simple"})
*/
protected $discount = 0;
/**
* @var User[]
* @ORM\OneToMany(targetEntity="User", mappedBy="company")
* @Groups({"company_write", "company_read"})
* @MaxDepth(1)
*/
protected $employees;
/**
* @var Address
* @ORM\OneToOne(targetEntity="Address", cascade={"persist"})
* @Groups({"list", "read", "company_write", "company_read", "company_simple"})
*/
protected $address;
/**
* @var Address
* @ORM\OneToOne(targetEntity="Address", cascade={"persist"})
* @Groups({"list", "read", "company_write", "company_read"})
*/
protected $deliveryAddress;
/**
* @var Address
* @ORM\OneToOne(targetEntity="Address", cascade={"persist"})
* @Groups({"read", "company_write", "company_read"})
*/
protected $billingAddress;
/**
* @ORM\Column(type="string", nullable=true)
* @Groups({"list", "read", "write", "company_write", "company_read", "company_simple"})
*/
protected $logo;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Company", cascade={"persist"}, fetch="EAGER")
* @Groups({"list", "read", "company_write", "company_read"})
* @ORM\JoinColumn(onDelete="SET NULL")
* @ApiProperty(readableLink=false, writableLink=false)
*/
protected $distributor;
/**
* @Orm\Column(type="string", nullable=true)
* @Groups({"list", "company_write", "company_read", "read", "write", "company_simple"})
*/
protected $erpReference;
/**
* @Orm\Column(type="string", nullable=true)
* @Groups({"read", "company_write", "company_read", "company_simple"})
*/
protected $certification;
/**
* @ORM\ManyToMany(targetEntity=Group::class, inversedBy="companies")
* @ORM\JoinTable(name="core_company_group")
*/
protected $groups;
/**
* @ORM\OneToMany(targetEntity=CompanyAttributeValue::class, mappedBy="company", orphanRemoval=true, cascade={"persist"})
*/
protected $attributeValues;
public function __construct()
{
$this->employees = new \Doctrine\Common\Collections\ArrayCollection();
$this->groups = new ArrayCollection();
$this->address = new Address();
$this->deliveryAddress = new Address();
$this->deliveryAddress->setActive(false);
$this->billingAddress = new Address();
$this->billingAddress->setActive(false);
$this->attributeValues = new ArrayCollection();
$this->groups = new ArrayCollection();
}
public function __toString()
{
return $this->name;
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @param mixed $id
*/
public function setId($id)
{
$this->id = $id;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* @return mixed
*/
public function getTaxId()
{
return $this->taxId;
}
/**
* @param mixed $taxId
*/
public function setTaxId($taxId)
{
$this->taxId = $taxId;
}
/**
* @return mixed
*/
public function getVerified()
{
return $this->verified;
}
/**
* @param mixed $verified
*/
public function setVerified($verified)
{
$this->verified = $verified;
}
/**
* @return bool
*/
public function getBlocked()
{
return $this->blocked;
}
/**
* @param bool $blocked
*/
public function setBlocked($blocked)
{
$this->blocked = (bool) $blocked;
}
/**
* @return string
*/
public function getCurrency()
{
return $this->currency;
}
/**
* @param string $currency
*/
public function setCurrency($currency)
{
$this->currency = $currency;
}
/**
* @return string
*/
public function getLanguage()
{
return $this->language;
}
/**
* @param string $language
*/
public function setLanguage($language)
{
$this->language = $language;
}
/**
* @return int
*/
public function getDiscount()
{
return $this->discount;
}
/**
* @param int $discount
*/
public function setDiscount($discount)
{
$this->discount = $discount;
}
/**
* @return User[]
*/
public function getEmployees()
{
return $this->employees;
}
/**
* @param mixed $employees
*/
public function setEmployees($employees)
{
$this->employees = $employees;
}
/**
* @return mixed
*/
public function getAddress()
{
return $this->address;
}
/**
* @param mixed $address
*/
public function setAddress($address)
{
$this->address = $address;
}
/**
* @return Address
*/
public function getDeliveryAddress()
{
return $this->deliveryAddress;
}
/**
* @param Address $deliveryAddress
*/
public function setDeliveryAddress($deliveryAddress)
{
$this->deliveryAddress = $deliveryAddress;
}
/**
* @return Address
*/
public function getBillingAddress()
{
return $this->billingAddress;
}
/**
* @param Address $billingAddress
*/
public function setBillingAddress($billingAddress)
{
$this->billingAddress = $billingAddress;
}
/**
* @return mixed
*/
public function getLogo()
{
return $this->logo;
}
/**
* @param mixed $logo
*/
public function setLogo($logo)
{
$this->logo = $logo;
}
/**
* @return mixed
*/
public function getDistributor()
{
return $this->distributor;
}
/**
* @param mixed $distributor
*/
public function setDistributor($distributor)
{
$this->distributor = $distributor;
}
/**
* @return mixed
*/
public function getErpReference()
{
return $this->erpReference;
}
/**
* @param mixed $erpReference
*/
public function setErpReference($erpReference)
{
$this->erpReference = $erpReference;
}
/**
* @return mixed
*/
public function getCertification()
{
return $this->certification;
}
/**
* @param mixed $certification
*/
public function setCertification($certification): void
{
$this->certification = $certification;
}
/**
* @return Collection|Group[]
*/
public function getGroups(): Collection
{
return $this->groups;
}
public function addGroup(Group $group): self
{
if (!$this->groups->contains($group)) {
$this->groups[] = $group;
}
return $this;
}
public function removeGroup(Group $group): self
{
$this->groups->removeElement($group);
return $this;
}
public function newValue(AttributeInterface $attribute): AttributeValueInterface
{
return new CompanyAttributeValue($attribute);
}
public function getAttributeValues(): Collection
{
return $this->attributeValues;
}
public function setAttributeValues(Collection $collection): AttributeValueAwareInterface
{
$this->attributeValues = $collection;
return $this;
}
}