src/Entity/Slave/Warehouse.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Slave;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Table(name="eposm_s_warehouse")
  9.  * @ORM\Entity(repositoryClass="App\Repository\Slave\WarehouseRepository")
  10.  */
  11. class Warehouse
  12. {    
  13.     public function __toString()
  14.                                                                                                                                                                                                                                                                             {
  15.                                                                                                                                                                                                                                                                                 $string '';
  16.                                                                                                                                                                                                                                                                                 if($this->getNickname() != null$string $this->getNickname();
  17.                                                                                                                                                                                                                                                                                 if($string != null) return $string;
  18.                                                                                                                                                                                                                                                                                 else return 'Magazzino - '.$this->getClient()->getName();
  19.                                                                                                                                                                                                                                                                             }
  20.     public function canDelete(){
  21.         if(sizeof($this->getProducts()) > 0) return false;
  22.         if(sizeof($this->getTransfersFrom()) > 0) return false;
  23.         if(sizeof($this->getTransfersTo()) > 0) return false;
  24.         if(sizeof($this->getProductRequests()) > 0) return false;
  25.         if(sizeof($this->getHeadquarterProductRequests()) > 0) return false;
  26.         if(sizeof($this->getInterventions()) > 0) return false;
  27.         return true;
  28.     }
  29.     public function displayType(){
  30.         if($this->getClient() != null) return 'Cliente';
  31.         if($this->getDestination() != null) return 'Destinazione';
  32.         if($this->isHeadquarter()) return 'Sede';
  33.         if($this->getClient() == null && $this->getDestination() == null && $this->isHeadquarter() == 0) return 'Tecnico';
  34.     }
  35.     public function getCanEdit($user){
  36.         $canSeeAll false;
  37.         foreach($user->getAccountType()->getPermissions() as $jtatp){
  38.             if($jtatp->getPermission()->getSlug() == 'warehouse' && $jtatp->getRw() == 'RW'){
  39.                 $canSeeAll true;
  40.             }
  41.         }
  42.         if($canSeeAll || str_contains($this->getJtUser($user->getId())->getPermission(), 'W')) return true;
  43.         return false;
  44.     }
  45.     public function getCanDelete($user){
  46.         if(sizeof($this->products) > 0) return false;
  47.         if(sizeof($this->transfersFrom) > 0) return false;
  48.         if(sizeof($this->transfersTo) > 0) return false;
  49.         $canSeeAll false;
  50.         foreach($user->getAccountType()->getPermissions() as $jtatp){
  51.             if($jtatp->getPermission()->getSlug() == 'warehouse' && $jtatp->getRw() == 'RW'){
  52.                 $canSeeAll true;
  53.             }
  54.         }
  55.         if($canSeeAll || str_contains($this->getJtUser($user->getId())->getPermission(), 'W')) return true;
  56.         return false;
  57.     }
  58.     public function getJtUser($userId){
  59.         foreach($this->users as $jtuw){
  60.             if($jtuw->getUser()->getId() == $userId)
  61.                 return $jtuw;
  62.         }
  63.         return null;
  64.     }
  65.     /**
  66.      * @ORM\Column(name="id", type="bigint")
  67.      * @ORM\Id
  68.      * @ORM\GeneratedValue(strategy="AUTO")
  69.      */
  70.     protected $id;
  71.     
  72.     /**
  73.      * @ORM\Column(name="nickname", type="string", length=191, nullable=true)
  74.      */
  75.     protected $nickname;
  76.     
  77.     /**
  78.      * @ORM\Column(name="address", type="string", length=191, nullable=true)
  79.      */
  80.     protected $address;
  81.     
  82.     /**
  83.      * @ORM\Column(name="is_movable", type="boolean")
  84.      */
  85.     protected $movable;
  86.     
  87.     /**
  88.      * @ORM\Column(name="is_headquarter", type="boolean")
  89.      */
  90.     protected $headquarter false;
  91.     
  92.     /**
  93.      * @ORM\Column(name="is_active", type="boolean")
  94.      */
  95.     protected $active true;
  96.         
  97.     // OneToOne
  98.         /**
  99.          * @ORM\OneToOne(targetEntity="App\Entity\Slave\Client", inversedBy="warehouse")
  100.          * @ORM\JoinColumn(name="client_id", referencedColumnName="id")
  101.          */
  102.         private $client;
  103.         /**
  104.          * @ORM\OneToOne(targetEntity="App\Entity\Slave\Destination", inversedBy="warehouse")
  105.          * @ORM\JoinColumn(name="destination_id", referencedColumnName="id")
  106.          */
  107.         private $destination;
  108.     //
  109.     // OneToMany
  110.         /**
  111.          * @ORM\OneToMany(targetEntity="App\Entity\Slave\JoinTableUserWarehouse", mappedBy="warehouse")
  112.          */
  113.         private $users;
  114.         /**
  115.          * @ORM\OneToMany(targetEntity="App\Entity\Slave\Product", mappedBy="actualWarehouse")
  116.          */
  117.         private $products;
  118.         
  119.         /**
  120.          * @ORM\OneToMany(targetEntity="App\Entity\Slave\ProductTransfer", mappedBy="warehouseFrom")
  121.          */
  122.         private $transfersFrom;
  123.         /**
  124.          * @ORM\OneToMany(targetEntity="App\Entity\Slave\ProductTransfer", mappedBy="warehouseTo")
  125.          */
  126.         private $transfersTo;
  127.         /**
  128.          * @ORM\OneToMany(targetEntity="App\Entity\Slave\ProductRequest", mappedBy="warehouse")
  129.          */
  130.         private $productRequests;
  131.         /**
  132.          * @ORM\OneToMany(targetEntity="App\Entity\Slave\ProductRequest", mappedBy="warehouseHeadquarter")
  133.          */
  134.         private $headquarterProductRequests;
  135.         
  136.         /**
  137.          * @ORM\OneToMany(targetEntity="App\Entity\Slave\Intervention", mappedBy="warehouse")
  138.          */
  139.         private $interventions;
  140.         public function __construct()
  141.         {
  142.             $this->users = new ArrayCollection();
  143.             $this->products = new ArrayCollection();
  144.             $this->transfersFrom = new ArrayCollection();
  145.             $this->transfersTo = new ArrayCollection();
  146.             $this->productRequests = new ArrayCollection();
  147.             $this->headquarterProductRequests = new ArrayCollection();
  148.             $this->interventions = new ArrayCollection();
  149.         }
  150.     //
  151.     public function getId(): ?string
  152.     {
  153.         return $this->id;
  154.     }
  155.     public function getNickname(): ?string
  156.     {
  157.         return $this->nickname;
  158.     }
  159.     public function setNickname(?string $nickname): static
  160.     {
  161.         $this->nickname $nickname;
  162.         return $this;
  163.     }
  164.     public function getAddress(): ?string
  165.     {
  166.         return $this->address;
  167.     }
  168.     public function setAddress(?string $address): static
  169.     {
  170.         $this->address $address;
  171.         return $this;
  172.     }
  173.     public function isMovable(): ?bool
  174.     {
  175.         return $this->movable;
  176.     }
  177.     public function setMovable(bool $movable): static
  178.     {
  179.         $this->movable $movable;
  180.         return $this;
  181.     }
  182.     public function isHeadquarter(): ?bool
  183.     {
  184.         return $this->headquarter;
  185.     }
  186.     public function setHeadquarter(bool $headquarter): static
  187.     {
  188.         $this->headquarter $headquarter;
  189.         return $this;
  190.     }
  191.     public function isActive(): ?bool
  192.     {
  193.         return $this->active;
  194.     }
  195.     public function setActive(bool $active): static
  196.     {
  197.         $this->active $active;
  198.         return $this;
  199.     }
  200.     public function getClient(): ?Client
  201.     {
  202.         return $this->client;
  203.     }
  204.     public function setClient(?Client $client): static
  205.     {
  206.         $this->client $client;
  207.         return $this;
  208.     }
  209.     public function getDestination(): ?Destination
  210.     {
  211.         return $this->destination;
  212.     }
  213.     public function setDestination(?Destination $destination): static
  214.     {
  215.         $this->destination $destination;
  216.         return $this;
  217.     }
  218.     /**
  219.      * @return Collection<int, JoinTableUserWarehouse>
  220.      */
  221.     public function getUsers(): Collection
  222.     {
  223.         return $this->users;
  224.     }
  225.     public function addUser(JoinTableUserWarehouse $user): static
  226.     {
  227.         if (!$this->users->contains($user)) {
  228.             $this->users->add($user);
  229.             $user->setWarehouse($this);
  230.         }
  231.         return $this;
  232.     }
  233.     public function removeUser(JoinTableUserWarehouse $user): static
  234.     {
  235.         if ($this->users->removeElement($user)) {
  236.             // set the owning side to null (unless already changed)
  237.             if ($user->getWarehouse() === $this) {
  238.                 $user->setWarehouse(null);
  239.             }
  240.         }
  241.         return $this;
  242.     }
  243.     /**
  244.      * @return Collection<int, Product>
  245.      */
  246.     public function getProducts(): Collection
  247.     {
  248.         return $this->products;
  249.     }
  250.     public function addProduct(Product $product): static
  251.     {
  252.         if (!$this->products->contains($product)) {
  253.             $this->products->add($product);
  254.             $product->setActualWarehouse($this);
  255.         }
  256.         return $this;
  257.     }
  258.     public function removeProduct(Product $product): static
  259.     {
  260.         if ($this->products->removeElement($product)) {
  261.             // set the owning side to null (unless already changed)
  262.             if ($product->getActualWarehouse() === $this) {
  263.                 $product->setActualWarehouse(null);
  264.             }
  265.         }
  266.         return $this;
  267.     }
  268.     /**
  269.      * @return Collection<int, ProductTransfer>
  270.      */
  271.     public function getTransfersFrom(): Collection
  272.     {
  273.         return $this->transfersFrom;
  274.     }
  275.     public function addTransfersFrom(ProductTransfer $transfersFrom): static
  276.     {
  277.         if (!$this->transfersFrom->contains($transfersFrom)) {
  278.             $this->transfersFrom->add($transfersFrom);
  279.             $transfersFrom->setWarehouseFrom($this);
  280.         }
  281.         return $this;
  282.     }
  283.     public function removeTransfersFrom(ProductTransfer $transfersFrom): static
  284.     {
  285.         if ($this->transfersFrom->removeElement($transfersFrom)) {
  286.             // set the owning side to null (unless already changed)
  287.             if ($transfersFrom->getWarehouseFrom() === $this) {
  288.                 $transfersFrom->setWarehouseFrom(null);
  289.             }
  290.         }
  291.         return $this;
  292.     }
  293.     /**
  294.      * @return Collection<int, ProductTransfer>
  295.      */
  296.     public function getTransfersTo(): Collection
  297.     {
  298.         return $this->transfersTo;
  299.     }
  300.     public function addTransfersTo(ProductTransfer $transfersTo): static
  301.     {
  302.         if (!$this->transfersTo->contains($transfersTo)) {
  303.             $this->transfersTo->add($transfersTo);
  304.             $transfersTo->setWarehouseTo($this);
  305.         }
  306.         return $this;
  307.     }
  308.     public function removeTransfersTo(ProductTransfer $transfersTo): static
  309.     {
  310.         if ($this->transfersTo->removeElement($transfersTo)) {
  311.             // set the owning side to null (unless already changed)
  312.             if ($transfersTo->getWarehouseTo() === $this) {
  313.                 $transfersTo->setWarehouseTo(null);
  314.             }
  315.         }
  316.         return $this;
  317.     }
  318.     /**
  319.      * @return Collection<int, ProductRequest>
  320.      */
  321.     public function getProductRequests(): Collection
  322.     {
  323.         return $this->productRequests;
  324.     }
  325.     public function addProductRequest(ProductRequest $productRequest): static
  326.     {
  327.         if (!$this->productRequests->contains($productRequest)) {
  328.             $this->productRequests->add($productRequest);
  329.             $productRequest->setWarehouse($this);
  330.         }
  331.         return $this;
  332.     }
  333.     public function removeProductRequest(ProductRequest $productRequest): static
  334.     {
  335.         if ($this->productRequests->removeElement($productRequest)) {
  336.             // set the owning side to null (unless already changed)
  337.             if ($productRequest->getWarehouse() === $this) {
  338.                 $productRequest->setWarehouse(null);
  339.             }
  340.         }
  341.         return $this;
  342.     }
  343.     /**
  344.      * @return Collection<int, ProductRequest>
  345.      */
  346.     public function getHeadquarterProductRequests(): Collection
  347.     {
  348.         return $this->headquarterProductRequests;
  349.     }
  350.     public function addHeadquarterProductRequest(ProductRequest $headquarterProductRequest): static
  351.     {
  352.         if (!$this->headquarterProductRequests->contains($headquarterProductRequest)) {
  353.             $this->headquarterProductRequests->add($headquarterProductRequest);
  354.             $headquarterProductRequest->setWarehouseHeadquarter($this);
  355.         }
  356.         return $this;
  357.     }
  358.     public function removeHeadquarterProductRequest(ProductRequest $headquarterProductRequest): static
  359.     {
  360.         if ($this->headquarterProductRequests->removeElement($headquarterProductRequest)) {
  361.             // set the owning side to null (unless already changed)
  362.             if ($headquarterProductRequest->getWarehouseHeadquarter() === $this) {
  363.                 $headquarterProductRequest->setWarehouseHeadquarter(null);
  364.             }
  365.         }
  366.         return $this;
  367.     }
  368.     /**
  369.      * @return Collection<int, Intervention>
  370.      */
  371.     public function getInterventions(): Collection
  372.     {
  373.         return $this->interventions;
  374.     }
  375.     public function addIntervention(Intervention $intervention): static
  376.     {
  377.         if (!$this->interventions->contains($intervention)) {
  378.             $this->interventions->add($intervention);
  379.             $intervention->setWarehouse($this);
  380.         }
  381.         return $this;
  382.     }
  383.     public function removeIntervention(Intervention $intervention): static
  384.     {
  385.         if ($this->interventions->removeElement($intervention)) {
  386.             // set the owning side to null (unless already changed)
  387.             if ($intervention->getWarehouse() === $this) {
  388.                 $intervention->setWarehouse(null);
  389.             }
  390.         }
  391.         return $this;
  392.     }
  393. }