<?php
namespace App\AtechNet\CoreBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\OrderBy;
use Doctrine\ORM\Mapping\Table as Table;
/**
* Stock
*
* @Table(name="stocks")
* @Entity
*/
class Stock extends AbstractSignedEntity
{
public const DEFAULT_ID = 1;
/**
* @var Company
*
* @ManyToOne(targetEntity="Company", inversedBy="stocks")
* @JoinColumn(name="company_id", referencedColumnName="id", nullable=false)
*/
private $company;
/**
* @var string
*
* @Column(name="code", type="string", length=24)
*/
private $code;
/**
* @var string
*
* @Column(name="title", type="string", length=128)
*/
private $title;
/**
* @var string
*
* @Column(name="street", type="string", length=64)
*/
private $street;
/**
* @var string
*
* @Column(name="city", type="string", length=64)
*/
private $city;
/**
* @var string
*
* @Column(name="zip", type="string", length=8)
*/
private $zip;
/**
* @var string
*
* @Column(name="country", type="string", length=24)
*/
private $country;
/**
* @var string
*
* @Column(name="gps", type="string", length=24)
*/
private $gps;
/**
* @var ArrayCollection
*
* @OneToMany(targetEntity="StockMovement", mappedBy="stock", orphanRemoval=true)
* @OrderBy({"created" = "DESC"})
**/
private $movements;
/**
* @var ArrayCollection
*
* @OneToMany(targetEntity="StockPosition", mappedBy="stock", orphanRemoval=true)
* @OrderBy({"name" = "ASC"})
**/
private $stockPositions;
public function __construct()
{
parent::__construct();
$this->movements = new ArrayCollection();
$this->stockPositions = new ArrayCollection();
}
/**
* @return Company
*/
public function getCompany()
{
return $this->company;
}
/**
* @param Company $company
*/
public function setCompany($company)
{
$this->company = $company;
}
/**
* @return string
*/
public function getCode()
{
return $this->code;
}
/**
* @param string $code
*/
public function setCode($code)
{
$this->code = $code;
}
/**
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* @param string $title
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* @return string
*/
public function getStreet()
{
return $this->street;
}
/**
* @param string $street
*/
public function setStreet($street)
{
$this->street = $street;
}
/**
* @return string
*/
public function getCity()
{
return $this->city;
}
/**
* @param string $city
*/
public function setCity($city)
{
$this->city = $city;
}
/**
* @return string
*/
public function getZip()
{
return $this->zip;
}
/**
* @param string $zip
*/
public function setZip($zip)
{
$this->zip = $zip;
}
/**
* @return string
*/
public function getCountry()
{
return $this->country;
}
/**
* @param string $country
*/
public function setCountry($country)
{
$this->country = $country;
}
/**
* @return string
*/
public function getGps()
{
return $this->gps;
}
/**
* @param string $gps
*/
public function setGps($gps)
{
$this->gps = $gps;
}
/**
* @param bool $showRemoved
* @return Collection
*/
public function getMovements($showRemoved = false)
{
$criteria = Criteria::create();
if ($showRemoved !== true) {
$criteria->where(Criteria::expr()->eq('removed', false));
}
return $this->movements->matching($criteria);
}
/**
* @return Collection
*/
public function getStockPositions(): Collection
{
return $this->stockPositions;
}
}