src/AtechNet/CoreBundle/Entity/Stock.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\Common\Collections\Criteria;
  6. use Doctrine\ORM\Mapping\Column;
  7. use Doctrine\ORM\Mapping\Entity;
  8. use Doctrine\ORM\Mapping\JoinColumn;
  9. use Doctrine\ORM\Mapping\ManyToOne;
  10. use Doctrine\ORM\Mapping\OneToMany;
  11. use Doctrine\ORM\Mapping\OrderBy;
  12. use Doctrine\ORM\Mapping\Table as Table;
  13. /**
  14.  * Stock
  15.  *
  16.  * @Table(name="stocks")
  17.  * @Entity
  18.  */
  19. class Stock extends AbstractSignedEntity
  20. {
  21.     public const DEFAULT_ID = 1;
  22.     /**
  23.      * @var Company
  24.      *
  25.      * @ManyToOne(targetEntity="Company", inversedBy="stocks")
  26.      * @JoinColumn(name="company_id", referencedColumnName="id", nullable=false)
  27.      */
  28.     private $company;
  29.     /**
  30.      * @var string
  31.      *
  32.      * @Column(name="code", type="string", length=24)
  33.      */
  34.     private $code;
  35.     /**
  36.      * @var string
  37.      *
  38.      * @Column(name="title", type="string", length=128)
  39.      */
  40.     private $title;
  41.     /**
  42.      * @var string
  43.      *
  44.      * @Column(name="street", type="string", length=64)
  45.      */
  46.     private $street;
  47.     /**
  48.      * @var string
  49.      *
  50.      * @Column(name="city", type="string", length=64)
  51.      */
  52.     private $city;
  53.     /**
  54.      * @var string
  55.      *
  56.      * @Column(name="zip", type="string", length=8)
  57.      */
  58.     private $zip;
  59.     /**
  60.      * @var string
  61.      *
  62.      * @Column(name="country", type="string", length=24)
  63.      */
  64.     private $country;
  65.     /**
  66.      * @var string
  67.      *
  68.      * @Column(name="gps", type="string", length=24)
  69.      */
  70.     private $gps;
  71.     /**
  72.      * @var ArrayCollection
  73.      *
  74.      * @OneToMany(targetEntity="StockMovement", mappedBy="stock", orphanRemoval=true)
  75.      * @OrderBy({"created" = "DESC"})
  76.      **/
  77.     private $movements;
  78.     /**
  79.      * @var ArrayCollection
  80.      *
  81.      * @OneToMany(targetEntity="StockPosition", mappedBy="stock", orphanRemoval=true)
  82.      * @OrderBy({"name" = "ASC"})
  83.      **/
  84.     private $stockPositions;
  85.     public function __construct()
  86.     {
  87.         parent::__construct();
  88.         $this->movements = new ArrayCollection();
  89.         $this->stockPositions = new ArrayCollection();
  90.     }
  91.     /**
  92.      * @return Company
  93.      */
  94.     public function getCompany()
  95.     {
  96.         return $this->company;
  97.     }
  98.     /**
  99.      * @param Company $company
  100.      */
  101.     public function setCompany($company)
  102.     {
  103.         $this->company = $company;
  104.     }
  105.     /**
  106.      * @return string
  107.      */
  108.     public function getCode()
  109.     {
  110.         return $this->code;
  111.     }
  112.     /**
  113.      * @param string $code
  114.      */
  115.     public function setCode($code)
  116.     {
  117.         $this->code = $code;
  118.     }
  119.     /**
  120.      * @return string
  121.      */
  122.     public function getTitle()
  123.     {
  124.         return $this->title;
  125.     }
  126.     /**
  127.      * @param string $title
  128.      */
  129.     public function setTitle($title)
  130.     {
  131.         $this->title = $title;
  132.     }
  133.     /**
  134.      * @return string
  135.      */
  136.     public function getStreet()
  137.     {
  138.         return $this->street;
  139.     }
  140.     /**
  141.      * @param string $street
  142.      */
  143.     public function setStreet($street)
  144.     {
  145.         $this->street = $street;
  146.     }
  147.     /**
  148.      * @return string
  149.      */
  150.     public function getCity()
  151.     {
  152.         return $this->city;
  153.     }
  154.     /**
  155.      * @param string $city
  156.      */
  157.     public function setCity($city)
  158.     {
  159.         $this->city = $city;
  160.     }
  161.     /**
  162.      * @return string
  163.      */
  164.     public function getZip()
  165.     {
  166.         return $this->zip;
  167.     }
  168.     /**
  169.      * @param string $zip
  170.      */
  171.     public function setZip($zip)
  172.     {
  173.         $this->zip = $zip;
  174.     }
  175.     /**
  176.      * @return string
  177.      */
  178.     public function getCountry()
  179.     {
  180.         return $this->country;
  181.     }
  182.     /**
  183.      * @param string $country
  184.      */
  185.     public function setCountry($country)
  186.     {
  187.         $this->country = $country;
  188.     }
  189.     /**
  190.      * @return string
  191.      */
  192.     public function getGps()
  193.     {
  194.         return $this->gps;
  195.     }
  196.     /**
  197.      * @param string $gps
  198.      */
  199.     public function setGps($gps)
  200.     {
  201.         $this->gps = $gps;
  202.     }
  203.     /**
  204.      * @param bool $showRemoved
  205.      * @return Collection
  206.      */
  207.     public function getMovements($showRemoved = false)
  208.     {
  209.         $criteria = Criteria::create();
  210.         if ($showRemoved !== true) {
  211.             $criteria->where(Criteria::expr()->eq('removed', false));
  212.         }
  213.         return $this->movements->matching($criteria);
  214.     }
  215.     /**
  216.      * @return Collection
  217.      */
  218.     public function getStockPositions(): Collection
  219.     {
  220.         return $this->stockPositions;
  221.     }
  222. }