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.         public function getId(): ?string
  151.         {
  152.             return $this->id;
  153.         }
  154.         public function getNickname(): ?string
  155.         {
  156.             return $this->nickname;
  157.         }
  158.         public function setNickname(?string $nickname): static
  159.         {
  160.             $this->nickname $nickname;
  161.             return $this;
  162.         }
  163.         public function getAddress(): ?string
  164.         {
  165.             return $this->address;
  166.         }
  167.         public function setAddress(?string $address): static
  168.         {
  169.             $this->address $address;
  170.             return $this;
  171.         }
  172.         public function isMovable(): ?bool
  173.         {
  174.             return $this->movable;
  175.         }
  176.         public function setMovable(bool $movable): static
  177.         {
  178.             $this->movable $movable;
  179.             return $this;
  180.         }
  181.         public function isHeadquarter(): ?bool
  182.         {
  183.             return $this->headquarter;
  184.         }
  185.         public function setHeadquarter(bool $headquarter): static
  186.         {
  187.             $this->headquarter $headquarter;
  188.             return $this;
  189.         }
  190.         public function isActive(): ?bool
  191.         {
  192.             return $this->active;
  193.         }
  194.         public function setActive(bool $active): static
  195.         {
  196.             $this->active $active;
  197.             return $this;
  198.         }
  199.         public function getClient(): ?Client
  200.         {
  201.             return $this->client;
  202.         }
  203.         public function setClient(?Client $client): static
  204.         {
  205.             $this->client $client;
  206.             return $this;
  207.         }
  208.         public function getDestination(): ?Destination
  209.         {
  210.             return $this->destination;
  211.         }
  212.         public function setDestination(?Destination $destination): static
  213.         {
  214.             $this->destination $destination;
  215.             return $this;
  216.         }
  217.         /**
  218.          * @return Collection<int, JoinTableUserWarehouse>
  219.          */
  220.         public function getUsers(): Collection
  221.         {
  222.             return $this->users;
  223.         }
  224.         public function addUser(JoinTableUserWarehouse $user): static
  225.         {
  226.             if (!$this->users->contains($user)) {
  227.                 $this->users->add($user);
  228.                 $user->setWarehouse($this);
  229.             }
  230.             return $this;
  231.         }
  232.         public function removeUser(JoinTableUserWarehouse $user): static
  233.         {
  234.             if ($this->users->removeElement($user)) {
  235.                 // set the owning side to null (unless already changed)
  236.                 if ($user->getWarehouse() === $this) {
  237.                     $user->setWarehouse(null);
  238.                 }
  239.             }
  240.             return $this;
  241.         }
  242.         /**
  243.          * @return Collection<int, Product>
  244.          */
  245.         public function getProducts(): Collection
  246.         {
  247.             return $this->products;
  248.         }
  249.         public function addProduct(Product $product): static
  250.         {
  251.             if (!$this->products->contains($product)) {
  252.                 $this->products->add($product);
  253.                 $product->setActualWarehouse($this);
  254.             }
  255.             return $this;
  256.         }
  257.         public function removeProduct(Product $product): static
  258.         {
  259.             if ($this->products->removeElement($product)) {
  260.                 // set the owning side to null (unless already changed)
  261.                 if ($product->getActualWarehouse() === $this) {
  262.                     $product->setActualWarehouse(null);
  263.                 }
  264.             }
  265.             return $this;
  266.         }
  267.         /**
  268.          * @return Collection<int, ProductTransfer>
  269.          */
  270.         public function getTransfersFrom(): Collection
  271.         {
  272.             return $this->transfersFrom;
  273.         }
  274.         public function addTransfersFrom(ProductTransfer $transfersFrom): static
  275.         {
  276.             if (!$this->transfersFrom->contains($transfersFrom)) {
  277.                 $this->transfersFrom->add($transfersFrom);
  278.                 $transfersFrom->setWarehouseFrom($this);
  279.             }
  280.             return $this;
  281.         }
  282.         public function removeTransfersFrom(ProductTransfer $transfersFrom): static
  283.         {
  284.             if ($this->transfersFrom->removeElement($transfersFrom)) {
  285.                 // set the owning side to null (unless already changed)
  286.                 if ($transfersFrom->getWarehouseFrom() === $this) {
  287.                     $transfersFrom->setWarehouseFrom(null);
  288.                 }
  289.             }
  290.             return $this;
  291.         }
  292.         /**
  293.          * @return Collection<int, ProductTransfer>
  294.          */
  295.         public function getTransfersTo(): Collection
  296.         {
  297.             return $this->transfersTo;
  298.         }
  299.         public function addTransfersTo(ProductTransfer $transfersTo): static
  300.         {
  301.             if (!$this->transfersTo->contains($transfersTo)) {
  302.                 $this->transfersTo->add($transfersTo);
  303.                 $transfersTo->setWarehouseTo($this);
  304.             }
  305.             return $this;
  306.         }
  307.         public function removeTransfersTo(ProductTransfer $transfersTo): static
  308.         {
  309.             if ($this->transfersTo->removeElement($transfersTo)) {
  310.                 // set the owning side to null (unless already changed)
  311.                 if ($transfersTo->getWarehouseTo() === $this) {
  312.                     $transfersTo->setWarehouseTo(null);
  313.                 }
  314.             }
  315.             return $this;
  316.         }
  317.         /**
  318.          * @return Collection<int, ProductRequest>
  319.          */
  320.         public function getProductRequests(): Collection
  321.         {
  322.             return $this->productRequests;
  323.         }
  324.         public function addProductRequest(ProductRequest $productRequest): static
  325.         {
  326.             if (!$this->productRequests->contains($productRequest)) {
  327.                 $this->productRequests->add($productRequest);
  328.                 $productRequest->setWarehouse($this);
  329.             }
  330.             return $this;
  331.         }
  332.         public function removeProductRequest(ProductRequest $productRequest): static
  333.         {
  334.             if ($this->productRequests->removeElement($productRequest)) {
  335.                 // set the owning side to null (unless already changed)
  336.                 if ($productRequest->getWarehouse() === $this) {
  337.                     $productRequest->setWarehouse(null);
  338.                 }
  339.             }
  340.             return $this;
  341.         }
  342.         /**
  343.          * @return Collection<int, ProductRequest>
  344.          */
  345.         public function getHeadquarterProductRequests(): Collection
  346.         {
  347.             return $this->headquarterProductRequests;
  348.         }
  349.         public function addHeadquarterProductRequest(ProductRequest $headquarterProductRequest): static
  350.         {
  351.             if (!$this->headquarterProductRequests->contains($headquarterProductRequest)) {
  352.                 $this->headquarterProductRequests->add($headquarterProductRequest);
  353.                 $headquarterProductRequest->setWarehouseHeadquarter($this);
  354.             }
  355.             return $this;
  356.         }
  357.         public function removeHeadquarterProductRequest(ProductRequest $headquarterProductRequest): static
  358.         {
  359.             if ($this->headquarterProductRequests->removeElement($headquarterProductRequest)) {
  360.                 // set the owning side to null (unless already changed)
  361.                 if ($headquarterProductRequest->getWarehouseHeadquarter() === $this) {
  362.                     $headquarterProductRequest->setWarehouseHeadquarter(null);
  363.                 }
  364.             }
  365.             return $this;
  366.         }
  367.         /**
  368.          * @return Collection<int, Intervention>
  369.          */
  370.         public function getInterventions(): Collection
  371.         {
  372.             return $this->interventions;
  373.         }
  374.         public function addIntervention(Intervention $intervention): static
  375.         {
  376.             if (!$this->interventions->contains($intervention)) {
  377.                 $this->interventions->add($intervention);
  378.                 $intervention->setWarehouse($this);
  379.             }
  380.             return $this;
  381.         }
  382.         public function removeIntervention(Intervention $intervention): static
  383.         {
  384.             if ($this->interventions->removeElement($intervention)) {
  385.                 // set the owning side to null (unless already changed)
  386.                 if ($intervention->getWarehouse() === $this) {
  387.                     $intervention->setWarehouse(null);
  388.                 }
  389.             }
  390.             return $this;
  391.         }
  392. }