src/AtechNet/CoreBundle/Entity/StockPosition.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\AtechNet\CoreBundle\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping\Column;
  6. use Doctrine\ORM\Mapping\Entity;
  7. use Doctrine\ORM\Mapping\JoinColumn;
  8. use Doctrine\ORM\Mapping\ManyToOne;
  9. use Doctrine\ORM\Mapping\OneToMany;
  10. use Doctrine\ORM\Mapping\OrderBy;
  11. use Doctrine\ORM\Mapping\Table as Table;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. /**
  14.  * Stock positions
  15.  *
  16.  * @Entity(repositoryClass="App\AtechNet\CoreBundle\Repository\StockPositionRepository")
  17.  * @Table(name="stock_positions")
  18.  */
  19. class StockPosition extends AbstractSignedEntity
  20. {
  21.     public const string STOCK_POSITION_LIST_CACHE_KEY = 'stock_position_list.v8';
  22.     public const string STOCK_POSITION_LIST_STOCK_REQUEST_CACHE_KEY = 'stock_position_list_stock_request.v1';
  23.     public const int POSITION_ID_RAKTAR = 2117;
  24.     public const int POSITION_ID_CSOMAGOLAS = 2478;
  25.     public const int POSITION_ID_CSOMAGOLAS_VARO = 10921;
  26.     public const int POSITION_ID_TELEPITES_VARO = 2721;
  27.     public const int POSITION_ID_FOLIAZAS = 2720;
  28.     public const int POSITION_ID_FOLIAZAS_VARO = 2719;
  29.     public const int POSITION_ID_SERVIS_VARO = 2821;
  30.     public const int POSITION_ID_TISZTITAS = 2256;
  31.     public const int POSITION_ID_TISZTITAS_VARO = 2724;
  32.     public const int POSITION_ID_FUTAR_VARO = 10925;
  33.     public const int POSITION_ID_ALK_VARO = 10893;
  34.     public const int POSITION_ID_ORDER_STATUS_SWITCH = self::POSITION_ID_CSOMAGOLAS;
  35.     /**
  36.      * @var Stock
  37.      *
  38.      * @Assert\NotNull
  39.      *
  40.      * @ManyToOne(targetEntity="Stock", inversedBy="stockPositions")
  41.      * @JoinColumn(name="stock_id", referencedColumnName="id")
  42.      */
  43.     private $stock;
  44.     /**
  45.      * @var StockPositionGroup
  46.      *
  47.      * @ManyToOne(targetEntity="StockPositionGroup", inversedBy="stockPositions")
  48.      * @JoinColumn(name="stock_position_group_id", referencedColumnName="id", nullable=true)
  49.      */
  50.     private $stockPositionGroup;
  51.     /**
  52.      * @var string
  53.      *
  54.      * @Column(name="name", type="string", length=24)
  55.      */
  56.     private $name;
  57.     /**
  58.      * @var ArrayCollection
  59.      *
  60.      * @OneToMany(targetEntity="StockItemPosition", mappedBy="stockPosition", orphanRemoval=true)
  61.      * @OrderBy({"created" = "ASC"})
  62.      **/
  63.     private $items;
  64.     /**
  65.      * @var ArrayCollection
  66.      *
  67.      * @OneToMany(targetEntity="UserStockPosition", mappedBy="stockPosition", orphanRemoval=true)
  68.      * @OrderBy({"created" = "ASC"})
  69.      **/
  70.     private $users;
  71.     /**
  72.      * @var bool
  73.      *
  74.      * @Column(name="archived", type="boolean")
  75.      */
  76.     private $archived = 0;
  77.     /**
  78.      * @var bool
  79.      * 
  80.      * @Column(name="single", type="boolean", options={"default": false})
  81.      */
  82.     private bool $single = false;
  83.     /**
  84.      * @var ArrayCollection
  85.      *
  86.      * @OneToMany(targetEntity="StockReviewStockPosition", mappedBy="stockPosition", orphanRemoval=true)
  87.      */
  88.     private $stockReviews;
  89.     public function __construct()
  90.     {
  91.         parent::__construct();
  92.         $this->items = new ArrayCollection();
  93.         $this->users = new ArrayCollection();
  94.         $this->stockReviews = new ArrayCollection();
  95.     }
  96.     /**
  97.      * @return Stock|null
  98.      */
  99.     public function getStock(): ?Stock
  100.     {
  101.         return $this->stock;
  102.     }
  103.     /**
  104.      * @param Stock $stock
  105.      *
  106.      * @return void
  107.      */
  108.     public function setStock(Stock $stock): void
  109.     {
  110.         $this->stock = $stock;
  111.     }
  112.     /**
  113.      * @return StockPositionGroup|null
  114.      */
  115.     public function getStockPositionGroup(): ?StockPositionGroup
  116.     {
  117.         return $this->stockPositionGroup;
  118.     }
  119.     /**
  120.      * @param StockPositionGroup $stockPositionGroup
  121.      *
  122.      * @return void
  123.      */
  124.     public function setStockPositionGroup(StockPositionGroup $stockPositionGroup): void
  125.     {
  126.         $this->stockPositionGroup = $stockPositionGroup;
  127.     }
  128.     /**
  129.      * @return string
  130.      */
  131.     public function getName(): string
  132.     {
  133.         return $this->name;
  134.     }
  135.     /**
  136.      * @param string $name
  137.      *
  138.      * @return void
  139.      */
  140.     public function setName(string $name): void
  141.     {
  142.         $this->name = $name;
  143.     }
  144.     /**
  145.      * @return Collection
  146.      */
  147.     public function getStockItems(): Collection
  148.     {
  149.         return $this->items;
  150.     }
  151.     /**
  152.      * @return bool
  153.      */
  154.     public function hasStockItems(): bool
  155.     {
  156.         $stockItems = $this->getStockItems();
  157.         /** @var StockItemPosition $stockItemPosition */
  158.         foreach ($stockItems as $stockItemPosition) {
  159.             if ($stockItemPosition->getStockItem()->getLastKnownStockPosition()->getId() === $this->getId()) {
  160.                 return true;
  161.             }
  162.         }
  163.         return false;
  164.     }
  165.     /**
  166.      * @return Collection
  167.      */
  168.     public function getUsers(): Collection
  169.     {
  170.         return $this->users;
  171.     }
  172.     /**
  173.      * @return bool
  174.      */
  175.     public function hasUsers(): bool
  176.     {
  177.         if ($this->getUsers()->count() > 0) {
  178.             return true;
  179.         }
  180.         return false;
  181.     }
  182.     /**
  183.      * @return Collection
  184.      */
  185.     public function getStockReviews(): Collection
  186.     {
  187.         return $this->stockReviews;
  188.     }
  189.     /**
  190.      * @return bool
  191.      */
  192.     public function hasStockReviews(): bool
  193.     {
  194.         if ($this->getStockReviews()->count() > 0) {
  195.             return true;
  196.         }
  197.         return false;
  198.     }
  199.     /**
  200.     * @return bool
  201.     */
  202.     public function isArchived(): bool
  203.     {
  204.         return $this->archived;
  205.     }
  206.     /**
  207.      * @param bool $archived
  208.      *
  209.      * @return void
  210.      */
  211.     public function setArchived(bool $archived): void
  212.     {
  213.         $this->archived = $archived;
  214.     }
  215.     /**
  216.      * @return bool
  217.      */
  218.     public function isSingle(): bool
  219.     {
  220.         return $this->single;
  221.     }
  222.     /**
  223.      * @param bool $single
  224.      * 
  225.      * @return void
  226.      */
  227.     public function setSingle(bool $single): void
  228.     {
  229.         $this->single = $single;
  230.     }
  231.     /**
  232.      * @return bool
  233.      */
  234.     public function isTriage(): bool
  235.     {
  236.         if (
  237.             str_starts_with($this->name, 'T010-') || 
  238.             str_starts_with($this->name, 'T011-') || 
  239.             str_starts_with($this->name, 'T012-') || 
  240.             str_starts_with($this->name, 'T013-') || 
  241.             str_starts_with($this->name, 'T020-') || 
  242.             str_starts_with($this->name, 'T021-') || 
  243.             str_starts_with($this->name, 'T022-') || 
  244.             str_starts_with($this->name, 'T023-') 
  245.         ) {
  246.             $stockPositionName = explode('-', $this->name);
  247.             $suffix = array_pop($stockPositionName);
  248.             if (( (int)$suffix % 2 ) == 0 ) {
  249.                 return true;
  250.             }
  251.         }
  252.         return false;
  253.     }
  254. }