<?php
namespace App\Entity;
use App\Repository\StockProductRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass=StockProductRepository::class)
* @Vich\Uploadable
*/
class StockProduct
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=128)
*/
private $name;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $sale_price;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $purchase_price;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $quantity_available_for_kit;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $quantity_available_for_out;
/**
* @ORM\Column(type="boolean", options={"default": false})
*/
private $is_available_for_restaurant = false;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $restaurant_price;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $quantity_available_for_restaurant;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $image;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
* @Vich\UploadableField(mapping="stock_products", fileNameProperty="image")
* @var File|null
*/
private $imageFile;
/**
* @ORM\ManyToOne(targetEntity=Establishment::class, inversedBy="stockProducts")
* @ORM\JoinColumn(nullable=false)
*/
private $establishment;
/**
* @ORM\Column(type="datetime_immutable")
*/
private $created_at;
/**
* @ORM\Column(type="datetime_immutable")
*/
private $updated_at;
/**
* @ORM\Column(type="integer")
*/
private $created_by;
/**
* @ORM\Column(type="integer")
*/
private $updated_by;
/**
* @ORM\OneToMany(targetEntity=StockKitProduct::class, mappedBy="product")
*/
private $stockKitProducts;
/**
* @ORM\OneToMany(targetEntity=StockProductEntryLine::class, mappedBy="product")
*/
private $stockProductEntryLines;
/**
* @ORM\OneToMany(targetEntity=StockProviderKitEntryLine::class, mappedBy="product")
*/
private $stockProviderKitEntryLines;
/**
* @ORM\OneToMany(targetEntity=StockStudentKitEntryLine::class, mappedBy="product")
*/
private $stockStudentKitEntryLines;
/**
* @ORM\OneToMany(targetEntity=StockKitOutLine::class, mappedBy="product")
*/
private $stockKitOutLines;
/**
* @ORM\OneToMany(targetEntity=StockProductOut::class, mappedBy="product")
*/
private $stockProductOuts;
/**
* @ORM\OneToMany(targetEntity=StockMovement::class, mappedBy="stockProduct")
*/
private $stockMovements;
/**
* @ORM\OneToMany(targetEntity=StockDeliveryNoteLine::class, mappedBy="stockProduct")
*/
private $stockDeliveryNoteLines;
/**
* @ORM\OneToMany(targetEntity=StockReceptionVoucherLine::class, mappedBy="stockProduct")
*/
private $stockReceptionVoucherLines;
/**
* @ORM\OneToMany(targetEntity=StockExitSlip::class, mappedBy="stockProduct")
*/
private $stockExitSlips;
/**
* @ORM\OneToMany(targetEntity=StockinventoryLine::class, mappedBy="stockProduct")
*/
private $stockinventoryLines;
/**
* @ORM\OneToMany(targetEntity=StocktransferLine::class, mappedBy="stockProduct")
*/
private $stocktransferLines;
public function __construct()
{
$this->stockKitProducts = new ArrayCollection();
$this->stockProductEntryLines = new ArrayCollection();
$this->stockProviderKitEntryLines = new ArrayCollection();
$this->stockStudentKitEntryLines = new ArrayCollection();
$this->stockKitOutLines = new ArrayCollection();
$this->stockProductOuts = new ArrayCollection();
$this->stockMovements = new ArrayCollection();
$this->stockDeliveryNoteLines = new ArrayCollection();
$this->stockReceptionVoucherLines = new ArrayCollection();
$this->stockExitSlips = new ArrayCollection();
$this->stockinventoryLines = new ArrayCollection();
$this->stocktransferLines = new ArrayCollection();
}
public function __toString()
{
return $this->name;
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getEstablishment(): ?Establishment
{
return $this->establishment;
}
public function setEstablishment(?Establishment $establishment): self
{
$this->establishment = $establishment;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeImmutable $created_at): self
{
$this->created_at = $created_at;
return $this;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updated_at;
}
public function setUpdatedAt(\DateTimeImmutable $updated_at): self
{
$this->updated_at = $updated_at;
return $this;
}
public function getCreatedBy(): ?int
{
return $this->created_by;
}
public function setCreatedBy(int $created_by): self
{
$this->created_by = $created_by;
return $this;
}
public function getUpdatedBy(): ?int
{
return $this->updated_by;
}
public function setUpdatedBy(int $updated_by): self
{
$this->updated_by = $updated_by;
return $this;
}
/**
* @return Collection|StockKitProduct[]
*/
public function getStockKitProducts(): Collection
{
return $this->stockKitProducts;
}
public function addStockKitProduct(StockKitProduct $stockKitProduct): self
{
if (!$this->stockKitProducts->contains($stockKitProduct)) {
$this->stockKitProducts[] = $stockKitProduct;
$stockKitProduct->setProduct($this);
}
return $this;
}
public function removeStockKitProduct(StockKitProduct $stockKitProduct): self
{
if ($this->stockKitProducts->removeElement($stockKitProduct)) {
// set the owning side to null (unless already changed)
if ($stockKitProduct->getProduct() === $this) {
$stockKitProduct->setProduct(null);
}
}
return $this;
}
/**
* @return Collection|StockProductEntryLine[]
*/
public function getStockProductEntryLines(): Collection
{
return $this->stockProductEntryLines;
}
public function addStockProductEntryLine(StockProductEntryLine $stockProductEntryLine): self
{
if (!$this->stockProductEntryLines->contains($stockProductEntryLine)) {
$this->stockProductEntryLines[] = $stockProductEntryLine;
$stockProductEntryLine->setProduct($this);
}
return $this;
}
public function removeStockProductEntryLine(StockProductEntryLine $stockProductEntryLine): self
{
if ($this->stockProductEntryLines->removeElement($stockProductEntryLine)) {
// set the owning side to null (unless already changed)
if ($stockProductEntryLine->getProduct() === $this) {
$stockProductEntryLine->setProduct(null);
}
}
return $this;
}
/**
* @return Collection|StockProviderKitEntryLine[]
*/
public function getStockProviderKitEntryLines(): Collection
{
return $this->stockProviderKitEntryLines;
}
public function addStockProviderKitEntryLine(StockProviderKitEntryLine $stockProviderKitEntryLine): self
{
if (!$this->stockProviderKitEntryLines->contains($stockProviderKitEntryLine)) {
$this->stockProviderKitEntryLines[] = $stockProviderKitEntryLine;
$stockProviderKitEntryLine->setProduct($this);
}
return $this;
}
public function removeStockProviderKitEntryLine(StockProviderKitEntryLine $stockProviderKitEntryLine): self
{
if ($this->stockProviderKitEntryLines->removeElement($stockProviderKitEntryLine)) {
// set the owning side to null (unless already changed)
if ($stockProviderKitEntryLine->getProduct() === $this) {
$stockProviderKitEntryLine->setProduct(null);
}
}
return $this;
}
/**
* @return Collection|StockStudentKitEntryLine[]
*/
public function getStockStudentKitEntryLines(): Collection
{
return $this->stockStudentKitEntryLines;
}
public function addStockStudentKitEntryLine(StockStudentKitEntryLine $stockStudentKitEntryLine): self
{
if (!$this->stockStudentKitEntryLines->contains($stockStudentKitEntryLine)) {
$this->stockStudentKitEntryLines[] = $stockStudentKitEntryLine;
$stockStudentKitEntryLine->setProduct($this);
}
return $this;
}
public function removeStockStudentKitEntryLine(StockStudentKitEntryLine $stockStudentKitEntryLine): self
{
if ($this->stockStudentKitEntryLines->removeElement($stockStudentKitEntryLine)) {
// set the owning side to null (unless already changed)
if ($stockStudentKitEntryLine->getProduct() === $this) {
$stockStudentKitEntryLine->setProduct(null);
}
}
return $this;
}
/**
* @return Collection|StockKitOutLine[]
*/
public function getStockKitOutLines(): Collection
{
return $this->stockKitOutLines;
}
public function addStockKitOutLine(StockKitOutLine $stockKitOutLine): self
{
if (!$this->stockKitOutLines->contains($stockKitOutLine)) {
$this->stockKitOutLines[] = $stockKitOutLine;
$stockKitOutLine->setProduct($this);
}
return $this;
}
public function removeStockKitOutLine(StockKitOutLine $stockKitOutLine): self
{
if ($this->stockKitOutLines->removeElement($stockKitOutLine)) {
// set the owning side to null (unless already changed)
if ($stockKitOutLine->getProduct() === $this) {
$stockKitOutLine->setProduct(null);
}
}
return $this;
}
/**
* @return Collection|StockProductOut[]
*/
public function getStockProductOuts(): Collection
{
return $this->stockProductOuts;
}
public function addStockProductOut(StockProductOut $stockProductOut): self
{
if (!$this->stockProductOuts->contains($stockProductOut)) {
$this->stockProductOuts[] = $stockProductOut;
$stockProductOut->setProduct($this);
}
return $this;
}
public function removeStockProductOut(StockProductOut $stockProductOut): self
{
if ($this->stockProductOuts->removeElement($stockProductOut)) {
// set the owning side to null (unless already changed)
if ($stockProductOut->getProduct() === $this) {
$stockProductOut->setProduct(null);
}
}
return $this;
}
public function getQuantityAvailableForKit(): ?float
{
return $this->quantity_available_for_kit;
}
public function setQuantityAvailableForKit(?float $quantity_available_for_kit): self
{
$this->quantity_available_for_kit = $quantity_available_for_kit;
return $this;
}
public function getQuantityAvailableForOut(): ?float
{
return $this->quantity_available_for_out;
}
public function setQuantityAvailableForOut(?float $quantity_available_for_out): self
{
$this->quantity_available_for_out = $quantity_available_for_out;
return $this;
}
public function getSalePrice(): ?float
{
return $this->sale_price;
}
public function setSalePrice(?float $sale_price): self
{
$this->sale_price = $sale_price;
return $this;
}
public function getPurchasePrice(): ?float
{
return $this->purchase_price;
}
public function setPurchasePrice(?float $purchase_price): self
{
$this->purchase_price = $purchase_price;
return $this;
}
/**
* @return Collection|StockMovement[]
*/
public function getStockMovements(): Collection
{
return $this->stockMovements;
}
public function addStockMovement(StockMovement $stockMovement): self
{
if (!$this->stockMovements->contains($stockMovement)) {
$this->stockMovements[] = $stockMovement;
$stockMovement->setStockProduct($this);
}
return $this;
}
public function removeStockMovement(StockMovement $stockMovement): self
{
if ($this->stockMovements->removeElement($stockMovement)) {
// set the owning side to null (unless already changed)
if ($stockMovement->getStockProduct() === $this) {
$stockMovement->setStockProduct(null);
}
}
return $this;
}
/**
* @return Collection|StockDeliveryNoteLine[]
*/
public function getStockDeliveryNoteLines(): Collection
{
return $this->stockDeliveryNoteLines;
}
public function addStockDeliveryNoteLine(StockDeliveryNoteLine $stockDeliveryNoteLine): self
{
if (!$this->stockDeliveryNoteLines->contains($stockDeliveryNoteLine)) {
$this->stockDeliveryNoteLines[] = $stockDeliveryNoteLine;
$stockDeliveryNoteLine->setStockProduct($this);
}
return $this;
}
public function removeStockDeliveryNoteLine(StockDeliveryNoteLine $stockDeliveryNoteLine): self
{
if ($this->stockDeliveryNoteLines->removeElement($stockDeliveryNoteLine)) {
// set the owning side to null (unless already changed)
if ($stockDeliveryNoteLine->getStockProduct() === $this) {
$stockDeliveryNoteLine->setStockProduct(null);
}
}
return $this;
}
/**
* @return Collection|StockReceptionVoucherLine[]
*/
public function getStockReceptionVoucherLines(): Collection
{
return $this->stockReceptionVoucherLines;
}
public function addStockReceptionVoucherLine(StockReceptionVoucherLine $stockReceptionVoucherLine): self
{
if (!$this->stockReceptionVoucherLines->contains($stockReceptionVoucherLine)) {
$this->stockReceptionVoucherLines[] = $stockReceptionVoucherLine;
$stockReceptionVoucherLine->setStockProduct($this);
}
return $this;
}
public function removeStockReceptionVoucherLine(StockReceptionVoucherLine $stockReceptionVoucherLine): self
{
if ($this->stockReceptionVoucherLines->removeElement($stockReceptionVoucherLine)) {
// set the owning side to null (unless already changed)
if ($stockReceptionVoucherLine->getStockProduct() === $this) {
$stockReceptionVoucherLine->setStockProduct(null);
}
}
return $this;
}
/**
* @return Collection|StockExitSlip[]
*/
public function getStockExitSlips(): Collection
{
return $this->stockExitSlips;
}
public function addStockExitSlip(StockExitSlip $stockExitSlip): self
{
if (!$this->stockExitSlips->contains($stockExitSlip)) {
$this->stockExitSlips[] = $stockExitSlip;
$stockExitSlip->setStockProduct($this);
}
return $this;
}
public function removeStockExitSlip(StockExitSlip $stockExitSlip): self
{
if ($this->stockExitSlips->removeElement($stockExitSlip)) {
// set the owning side to null (unless already changed)
if ($stockExitSlip->getStockProduct() === $this) {
$stockExitSlip->setStockProduct(null);
}
}
return $this;
}
/**
* @return Collection|StockinventoryLine[]
*/
public function getStockinventoryLines(): Collection
{
return $this->stockinventoryLines;
}
public function addStockinventoryLine(StockinventoryLine $stockinventoryLine): self
{
if (!$this->stockinventoryLines->contains($stockinventoryLine)) {
$this->stockinventoryLines[] = $stockinventoryLine;
$stockinventoryLine->setStockProduct($this);
}
return $this;
}
public function removeStockinventoryLine(StockinventoryLine $stockinventoryLine): self
{
if ($this->stockinventoryLines->removeElement($stockinventoryLine)) {
// set the owning side to null (unless already changed)
if ($stockinventoryLine->getStockProduct() === $this) {
$stockinventoryLine->setStockProduct(null);
}
}
return $this;
}
/**
* @return Collection|StocktransferLine[]
*/
public function getStocktransferLines(): Collection
{
return $this->stocktransferLines;
}
public function addStocktransferLine(StocktransferLine $stocktransferLine): self
{
if (!$this->stocktransferLines->contains($stocktransferLine)) {
$this->stocktransferLines[] = $stocktransferLine;
$stocktransferLine->setStockProduct($this);
}
return $this;
}
public function removeStocktransferLine(StocktransferLine $stocktransferLine): self
{
if ($this->stocktransferLines->removeElement($stocktransferLine)) {
// set the owning side to null (unless already changed)
if ($stocktransferLine->getStockProduct() === $this) {
$stocktransferLine->setStockProduct(null);
}
}
return $this;
}
public function computeQuantityInStock(): ?float
{
$quantity_in_stock = 0;
foreach ($this->getStockMovements() as $stockMovement) {
if($stockMovement->getType() === StockMovement::TYPE_ENTREE) {
$quantity_in_stock += $stockMovement->getQuantity();
}
}
return $quantity_in_stock;
}
public function computeQuantityOutStock(): ?float
{
$quantity_out_stock = 0;
foreach ($this->getStockMovements() as $stockMovement) {
if($stockMovement->getType() === StockMovement::TYPE_SORTIE) {
$quantity_out_stock += $stockMovement->getQuantity();
}
}
return $quantity_out_stock;
}
public function computeQuantityAvailable(): ?float
{
$quantity_available = $this->computeQuantityInStock() - $this->computeQuantityOutStock();
return $quantity_available;
}
public function computeQuantityInStockByWarehouse(StockWarehouse $stockWarehouse): ?float
{
$quantity_in_stock = 0;
foreach ($this->getStockMovements() as $stockMovement) {
if($stockMovement->getType() === StockMovement::TYPE_ENTREE && $stockMovement->getStockWarehouse()->getId() === $stockWarehouse->getId()) {
$quantity_in_stock += $stockMovement->getQuantity();
}
}
return $quantity_in_stock;
}
public function computeQuantityOutStockByWarehouse(StockWarehouse $stockWarehouse): ?float
{
$quantity_out_stock = 0;
foreach ($this->getStockMovements() as $stockMovement) {
if($stockMovement->getType() === StockMovement::TYPE_SORTIE && $stockMovement->getStockWarehouse()->getId() === $stockWarehouse->getId()) {
$quantity_out_stock += $stockMovement->getQuantity();
}
}
return $quantity_out_stock;
}
public function computeQuantityAvailableByWarehouse(StockWarehouse $stockWarehouse): ?float
{
$quantity_available = $this->computeQuantityInStockByWarehouse($stockWarehouse) - $this->computeQuantityOutStockByWarehouse($stockWarehouse);
return $quantity_available;
}
// Restaurant fields getters and setters
public function getIsAvailableForRestaurant(): ?bool
{
return $this->is_available_for_restaurant;
}
public function setIsAvailableForRestaurant(bool $is_available_for_restaurant): self
{
$this->is_available_for_restaurant = $is_available_for_restaurant;
return $this;
}
public function getRestaurantPrice(): ?float
{
return $this->restaurant_price;
}
public function setRestaurantPrice(?float $restaurant_price): self
{
$this->restaurant_price = $restaurant_price;
return $this;
}
public function getQuantityAvailableForRestaurant(): ?float
{
return $this->quantity_available_for_restaurant;
}
public function setQuantityAvailableForRestaurant(?float $quantity_available_for_restaurant): self
{
$this->quantity_available_for_restaurant = $quantity_available_for_restaurant;
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
public function getImageFile(): ?File
{
return $this->imageFile;
}
public function setImageFile(?File $imageFile = null): self
{
$this->imageFile = $imageFile;
// VERY IMPORTANT: It is required that at least one field changes if you are using Doctrine,
// otherwise the event listeners won't be called and the file is lost
if ($imageFile) {
// if 'updatedAt' is not defined in your entity, use another field
$this->updated_at = new \DateTimeImmutable();
}
return $this;
}
}