<?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_warehouse")
* @ORM\Entity(repositoryClass="App\Repository\Slave\WarehouseRepository")
*/
class Warehouse
{
public function __toString()
{
$string = '';
if($this->getNickname() != null) $string = $this->getNickname();
if($string != null) return $string;
else return 'Magazzino - '.$this->getClient()->getName();
}
public function canDelete(){
if(sizeof($this->getProducts()) > 0) return false;
if(sizeof($this->getTransfersFrom()) > 0) return false;
if(sizeof($this->getTransfersTo()) > 0) return false;
if(sizeof($this->getProductRequests()) > 0) return false;
if(sizeof($this->getHeadquarterProductRequests()) > 0) return false;
if(sizeof($this->getInterventions()) > 0) return false;
return true;
}
public function displayType(){
if($this->getClient() != null) return 'Cliente';
if($this->getDestination() != null) return 'Destinazione';
if($this->isHeadquarter()) return 'Sede';
if($this->getClient() == null && $this->getDestination() == null && $this->isHeadquarter() == 0) return 'Tecnico';
}
public function getCanEdit($user){
$canSeeAll = false;
foreach($user->getAccountType()->getPermissions() as $jtatp){
if($jtatp->getPermission()->getSlug() == 'warehouse' && $jtatp->getRw() == 'RW'){
$canSeeAll = true;
}
}
if($canSeeAll || str_contains($this->getJtUser($user->getId())->getPermission(), 'W')) return true;
return false;
}
public function getCanDelete($user){
if(sizeof($this->products) > 0) return false;
if(sizeof($this->transfersFrom) > 0) return false;
if(sizeof($this->transfersTo) > 0) return false;
$canSeeAll = false;
foreach($user->getAccountType()->getPermissions() as $jtatp){
if($jtatp->getPermission()->getSlug() == 'warehouse' && $jtatp->getRw() == 'RW'){
$canSeeAll = true;
}
}
if($canSeeAll || str_contains($this->getJtUser($user->getId())->getPermission(), 'W')) return true;
return false;
}
public function getJtUser($userId){
foreach($this->users as $jtuw){
if($jtuw->getUser()->getId() == $userId)
return $jtuw;
}
return null;
}
/**
* @ORM\Column(name="id", type="bigint")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="nickname", type="string", length=191, nullable=true)
*/
protected $nickname;
/**
* @ORM\Column(name="address", type="string", length=191, nullable=true)
*/
protected $address;
/**
* @ORM\Column(name="is_movable", type="boolean")
*/
protected $movable;
/**
* @ORM\Column(name="is_headquarter", type="boolean")
*/
protected $headquarter = false;
/**
* @ORM\Column(name="is_active", type="boolean")
*/
protected $active = true;
// OneToOne
/**
* @ORM\OneToOne(targetEntity="App\Entity\Slave\Client", inversedBy="warehouse")
* @ORM\JoinColumn(name="client_id", referencedColumnName="id")
*/
private $client;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Slave\Destination", inversedBy="warehouse")
* @ORM\JoinColumn(name="destination_id", referencedColumnName="id")
*/
private $destination;
//
// OneToMany
/**
* @ORM\OneToMany(targetEntity="App\Entity\Slave\JoinTableUserWarehouse", mappedBy="warehouse")
*/
private $users;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Slave\Product", mappedBy="actualWarehouse")
*/
private $products;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Slave\ProductTransfer", mappedBy="warehouseFrom")
*/
private $transfersFrom;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Slave\ProductTransfer", mappedBy="warehouseTo")
*/
private $transfersTo;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Slave\ProductRequest", mappedBy="warehouse")
*/
private $productRequests;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Slave\ProductRequest", mappedBy="warehouseHeadquarter")
*/
private $headquarterProductRequests;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Slave\Intervention", mappedBy="warehouse")
*/
private $interventions;
public function __construct()
{
$this->users = new ArrayCollection();
$this->products = new ArrayCollection();
$this->transfersFrom = new ArrayCollection();
$this->transfersTo = new ArrayCollection();
$this->productRequests = new ArrayCollection();
$this->headquarterProductRequests = new ArrayCollection();
$this->interventions = 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 getAddress(): ?string
{
return $this->address;
}
public function setAddress(?string $address): static
{
$this->address = $address;
return $this;
}
public function isMovable(): ?bool
{
return $this->movable;
}
public function setMovable(bool $movable): static
{
$this->movable = $movable;
return $this;
}
public function isHeadquarter(): ?bool
{
return $this->headquarter;
}
public function setHeadquarter(bool $headquarter): static
{
$this->headquarter = $headquarter;
return $this;
}
public function isActive(): ?bool
{
return $this->active;
}
public function setActive(bool $active): static
{
$this->active = $active;
return $this;
}
public function getClient(): ?Client
{
return $this->client;
}
public function setClient(?Client $client): static
{
$this->client = $client;
return $this;
}
public function getDestination(): ?Destination
{
return $this->destination;
}
public function setDestination(?Destination $destination): static
{
$this->destination = $destination;
return $this;
}
/**
* @return Collection<int, JoinTableUserWarehouse>
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(JoinTableUserWarehouse $user): static
{
if (!$this->users->contains($user)) {
$this->users->add($user);
$user->setWarehouse($this);
}
return $this;
}
public function removeUser(JoinTableUserWarehouse $user): static
{
if ($this->users->removeElement($user)) {
// set the owning side to null (unless already changed)
if ($user->getWarehouse() === $this) {
$user->setWarehouse(null);
}
}
return $this;
}
/**
* @return Collection<int, Product>
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(Product $product): static
{
if (!$this->products->contains($product)) {
$this->products->add($product);
$product->setActualWarehouse($this);
}
return $this;
}
public function removeProduct(Product $product): static
{
if ($this->products->removeElement($product)) {
// set the owning side to null (unless already changed)
if ($product->getActualWarehouse() === $this) {
$product->setActualWarehouse(null);
}
}
return $this;
}
/**
* @return Collection<int, ProductTransfer>
*/
public function getTransfersFrom(): Collection
{
return $this->transfersFrom;
}
public function addTransfersFrom(ProductTransfer $transfersFrom): static
{
if (!$this->transfersFrom->contains($transfersFrom)) {
$this->transfersFrom->add($transfersFrom);
$transfersFrom->setWarehouseFrom($this);
}
return $this;
}
public function removeTransfersFrom(ProductTransfer $transfersFrom): static
{
if ($this->transfersFrom->removeElement($transfersFrom)) {
// set the owning side to null (unless already changed)
if ($transfersFrom->getWarehouseFrom() === $this) {
$transfersFrom->setWarehouseFrom(null);
}
}
return $this;
}
/**
* @return Collection<int, ProductTransfer>
*/
public function getTransfersTo(): Collection
{
return $this->transfersTo;
}
public function addTransfersTo(ProductTransfer $transfersTo): static
{
if (!$this->transfersTo->contains($transfersTo)) {
$this->transfersTo->add($transfersTo);
$transfersTo->setWarehouseTo($this);
}
return $this;
}
public function removeTransfersTo(ProductTransfer $transfersTo): static
{
if ($this->transfersTo->removeElement($transfersTo)) {
// set the owning side to null (unless already changed)
if ($transfersTo->getWarehouseTo() === $this) {
$transfersTo->setWarehouseTo(null);
}
}
return $this;
}
/**
* @return Collection<int, ProductRequest>
*/
public function getProductRequests(): Collection
{
return $this->productRequests;
}
public function addProductRequest(ProductRequest $productRequest): static
{
if (!$this->productRequests->contains($productRequest)) {
$this->productRequests->add($productRequest);
$productRequest->setWarehouse($this);
}
return $this;
}
public function removeProductRequest(ProductRequest $productRequest): static
{
if ($this->productRequests->removeElement($productRequest)) {
// set the owning side to null (unless already changed)
if ($productRequest->getWarehouse() === $this) {
$productRequest->setWarehouse(null);
}
}
return $this;
}
/**
* @return Collection<int, ProductRequest>
*/
public function getHeadquarterProductRequests(): Collection
{
return $this->headquarterProductRequests;
}
public function addHeadquarterProductRequest(ProductRequest $headquarterProductRequest): static
{
if (!$this->headquarterProductRequests->contains($headquarterProductRequest)) {
$this->headquarterProductRequests->add($headquarterProductRequest);
$headquarterProductRequest->setWarehouseHeadquarter($this);
}
return $this;
}
public function removeHeadquarterProductRequest(ProductRequest $headquarterProductRequest): static
{
if ($this->headquarterProductRequests->removeElement($headquarterProductRequest)) {
// set the owning side to null (unless already changed)
if ($headquarterProductRequest->getWarehouseHeadquarter() === $this) {
$headquarterProductRequest->setWarehouseHeadquarter(null);
}
}
return $this;
}
/**
* @return Collection<int, Intervention>
*/
public function getInterventions(): Collection
{
return $this->interventions;
}
public function addIntervention(Intervention $intervention): static
{
if (!$this->interventions->contains($intervention)) {
$this->interventions->add($intervention);
$intervention->setWarehouse($this);
}
return $this;
}
public function removeIntervention(Intervention $intervention): static
{
if ($this->interventions->removeElement($intervention)) {
// set the owning side to null (unless already changed)
if ($intervention->getWarehouse() === $this) {
$intervention->setWarehouse(null);
}
}
return $this;
}
}