<?php
namespace App\Entity;
use App\Repository\ShopRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ShopRepository::class)
*/
class Shop
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=128)
*/
private $name;
/**
* @ORM\Column(type="string", length=128)
*/
private $country;
/**
* @ORM\Column(type="integer")
*/
private $wttId;
/**
* @ORM\ManyToMany(targetEntity=User::class, mappedBy="shops")
*/
private Collection $users;
/**
* @ORM\OneToMany(targetEntity=Order::class, mappedBy="shop")
*/
private $orders;
/**
* @ORM\Column(type="string", length=16, nullable=true)
*/
private $wttName;
/**
* @ORM\Column(type="text", length=16, nullable=true)
*/
private $logo = null;
/**
* @ORM\OneToMany(targetEntity=Stock::class, mappedBy="shop")
*/
private $stocks;
/**
* @ORM\Column(type="json", nullable=true)
*/
private $config = null;
/**
* @ORM\OneToMany(targetEntity=Company::class, mappedBy="shop")
*/
private $companies;
/**
* @ORM\OneToMany(targetEntity=ShopSetting::class, mappedBy="shop", cascade={"persist"})
*/
private $settings;
/**
* @ORM\OneToMany(targetEntity=Imei::class, mappedBy="shop")
*/
private $imeis;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $apikey;
/**
* @ORM\Column(type="string", length=255,nullable=true)
*/
private $loginHash;
/**
* @ORM\Column(type="string", length=16)
*/
private $channel;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $mailCopy;
/**
* @ORM\OneToMany(targetEntity=Coupon::class, mappedBy="shop")
*/
private $coupons;
/**
* @ORM\ManyToMany(targetEntity=Category::class, inversedBy="shops", cascade={"persist"})
*/
private Collection $categories;
/**
* @ORM\ManyToMany(targetEntity=Option::class, mappedBy="shops", cascade={"persist"})
*/
private Collection $options;
/**
* @ORM\ManyToMany(targetEntity=Status::class, inversedBy="shops", cascade={"persist"})
*/
private Collection $statuses;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $active;
private $vat;
public function __construct()
{
$this->users = new ArrayCollection();
$this->orders = new ArrayCollection();
$this->products = new ArrayCollection();
$this->stocks = new ArrayCollection();
$this->companies = new ArrayCollection();
$this->imeis = new ArrayCollection();
$this->settings = new ArrayCollection();
$this->coupons = new ArrayCollection();
$this->categories = new ArrayCollection();
$this->options = new ArrayCollection();
$this->statuses = new ArrayCollection();
}
public function __toString() {
if($this->name!='') {
return $this->getName();
}
return "new shop";
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getMachineName() {
$name=str_replace(' ','-',$this->getName());
return preg_replace("/[^A-Za-z0-9.-]/",'',$name);
}
public function getWttId(): ?int
{
return $this->wttId;
}
public function setWttId(int $wttId): self
{
$this->wttId = $wttId;
return $this;
}
/**
* @return Collection<int, User>
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(User $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
//$user->setShop($this);
$user->addShop($this);
}
return $this;
}
public function removeUser(User $user): self
{
if ($this->users->removeElement($user)) {
// set the owning side to null (unless already changed)
if ($user->getShop() === $this) {
//$user->setShop(null);
$user->removeShop($this);
}
}
return $this;
}
public function addOrder(Order $order): self
{
if (!$this->orders->contains($order)) {
$this->orders[] = $order;
$order->setShop($this);
}
return $this;
}
public function removeOrder(Order $order): self
{
if ($this->orders->removeElement($order)) {
// set the owning side to null (unless already changed)
if ($order->getShop() === $this) {
$order->setShop(null);
}
}
return $this;
}
public function getWttName(): ?string
{
return $this->wttName;
}
public function setWttName(string $wttName): self
{
$this->wttName = $wttName;
return $this;
}
/**
* @return Collection<int, Stock>
*/
public function getStocks(): Collection
{
return $this->stocks;
}
public function addStock(Stock $stock): self
{
if (!$this->stocks->contains($stock)) {
$this->stocks[] = $stock;
$stock->setShop($this);
}
return $this;
}
public function removeStock(Stock $stock): self
{
if ($this->stocks->removeElement($stock)) {
// set the owning side to null (unless already changed)
if ($stock->getShop() === $this) {
$stock->setShop(null);
}
}
return $this;
}
public function getConfig()
{
if(is_null($this->config)) {
return null;
}
return reset($this->config);
}
public function setConfig( $config): self
{
$this->config = $config;
return $this;
}
/**
* @return Collection<int, Company>
*/
public function getCompanies(): Collection
{
return $this->companies;
}
public function addCompany(Company $company): self
{
if (!$this->companies->contains($company)) {
$this->companies[] = $company;
$company->setShop($this);
}
return $this;
}
public function removeCompany(Company $company): self
{
if ($this->companies->removeElement($company)) {
// set the owning side to null (unless already changed)
if ($company->getShop() === $this) {
$company->setShop(null);
}
}
return $this;
}
/**
* @return Collection<int, ShopSetting>
*/
public function getSettings(): Collection
{
return $this->settings;
}
public function getSetting($machineName) {
foreach($this->getSettings() as $setting) {
if($setting->getSetting()->getMachineName()==$machineName) {
if($setting->getValue()=='false') {
return false;
}
return $setting->getValue();
}
}
return false;
}
public function addSetting(ShopSetting $setting): void
{
$setting->setShop($this);
$this->settings->add($setting);
/*if (!$this->settings->contains($setting)) {
$this->settings[] = $setting;
$setting->setUser($this);
}
return $this;
*/
}
public function removeSetting(ShopSetting $setting): void
{
/*if ($this->settings->removeElement($setting)) {
// set the owning side to null (unless already changed)
if ($setting->getUser() === $this) {
$setting->setUser(null);
}
}
return $this;*/
}
/**
* @return Collection<int, Imei>
*/
public function getImeis(): Collection
{
return $this->imeis;
}
public function addImei(Imei $imei): self
{
if (!$this->imeis->contains($imei)) {
$this->imeis[] = $imei;
$imei->setShop($this);
}
return $this;
}
public function removeImei(Imei $imei): self
{
if ($this->imeis->removeElement($imei)) {
// set the owning side to null (unless already changed)
if ($imei->getShop() === $this) {
$imei->setShop(null);
}
}
return $this;
}
public function getApikey(): ?string
{
return $this->apikey;
}
public function setApikey(string $apikey): self
{
$this->apikey = $apikey;
return $this;
}
public function getLoginHash(): ?string
{
return $this->loginHash;
}
public function setLoginHash(string $loginHash): self
{
$this->loginHash = $loginHash;
return $this;
}
public function getChannel(): ?string
{
return $this->channel;
}
public function setChannel(string $channel): self
{
$this->channel = $channel;
return $this;
}
public function getMailCopy(): ?string
{
return $this->mailCopy;
}
public function setMailCopy(?string $mailCopy): self
{
$this->mailCopy = $mailCopy;
return $this;
}
/**
* @return Collection<int, Coupon>
*/
public function getCoupons(): Collection
{
return $this->coupons;
}
public function addCoupon(Coupon $coupon): static
{
if (!$this->coupons->contains($coupon)) {
$this->coupons->add($coupon);
$coupon->setShop($this);
}
return $this;
}
public function removeCoupon(Coupon $coupon): static
{
if ($this->coupons->removeElement($coupon)) {
// set the owning side to null (unless already changed)
if ($coupon->getShop() === $this) {
$coupon->setShop(null);
}
}
return $this;
}
/**
* @return Collection<int, Order>
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function getLogo(): ?string
{
return $this->logo;
}
public function setLogo(?string $logo): self
{
$this->logo = $logo;
return $this;
}
public function getCountry(): ?string
{
return $this->country;
}
public function setCountry(string $country): static
{
$this->country = $country;
return $this;
}
public function getVat() {
$this->vat=20;
if($this->getCountry()=='es') {
$this->vat=21;
}
return $this->vat;
}
/**
* @return Collection<int, Category>
*/
public function getCategories(): Collection
{
return $this->categories;
}
public function addCategory(Category $category): static
{
if (!$this->categories->contains($category)) {
$this->categories->add($category);
$category->addShop($this);
}
return $this;
}
public function removeCategory(Category $category): static
{
if ($this->categories->removeElement($category)) {
$category->removeShop($this);
}
return $this;
}
/**
* @return Collection<int, Option>
*/
public function getOptions(): Collection
{
return $this->options;
}
public function addOption(Option $option): static
{
if (!$this->options->contains($option)) {
$this->options->add($option);
$option->addShop($this);
}
return $this;
}
public function removeOption(Option $option): static
{
if ($this->options->removeElement($option)) {
$option->removeShop($this);
}
return $this;
}
/**
* @return Collection<int, Status>
*/
public function getStatuses(): Collection
{
return $this->statuses;
}
public function addStatus(Status $status): static
{
if (!$this->statuses->contains($status)) {
$this->statuses->add($status);
}
return $this;
}
public function removeStatus(Status $status): static
{
$this->statuses->removeElement($status);
return $this;
}
public function getActive():bool
{
return $this->active;
}
public function setActive(bool $active):self
{
$this->active = $active;
return $this;
}
public function isActive(): ?bool
{
return $this->active;
}
}