<?php
namespace App\Entity\ECommerce;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\ECommerce\Traits\DatesTrait;
use JMS\Serializer\Annotation as JMS;
use Stringable;
/**
* DepotProduct
*
* @ORM\Table(name="depot_product")
* @ORM\Entity(repositoryClass="App\Repository\ECommerce\DepotProductRepository")
* @ORM\HasLifecycleCallbacks()
*/
class DepotProduct implements Stringable
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*
* @JMS\Groups({"depot_product_private", "view_depot_product"})
*/
private int $id;
/**
* @ORM\Column(name="remote_id", type="string", nullable=true)
*
* @JMS\Groups({"depot_product_private", "view_depot_product"})
*/
private ?string $remoteId = null;
/**
* @ORM\Column(name="quantity", type="integer")
*
* @JMS\Groups({"depot_product_private", "view_depot_product"})
*/
private int $quantity = 0;
/**
* @ORM\Column(name="minimal_quantity", type="integer")
*
* @JMS\Groups({"depot_product_private", "view_depot_product"})
*/
private ?int $minimalQuantity = null;
/**
* @ORM\Column(name="optimal_quantity", type="integer")
*
* @JMS\Groups({"depot_product_private", "view_depot_product"})
*/
private ?int $optimalQuantity = null;
/**
* @ORM\Column(name="price", type="float", nullable=false)
*/
private float $price = 0;
/**
* @ORM\Column(name="tax_rate", type="decimal", precision=10, scale=0)
*/
private string|float $taxRate = 0;
/**
* @ORM\Column(name="location", type="string", length=90, nullable=true)
*/
protected string $location;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\ECommerce\Product", inversedBy="quantities")
* @ORM\JoinColumn(name="product", referencedColumnName="id")
*
* @JMS\Groups({"depot_product_private", "view_depot_product"})
*/
private ?Product $product = null;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\ECommerce\Depot", inversedBy="products")
* @ORM\JoinColumn(name="depot", referencedColumnName="id")
*/
private ?Depot $depot = null;
use DatesTrait {
DatesTrait::__construct as __DTConstruct;
}
public function __construct()
{
$this->__DTConstruct();
}
public function __toString(): string
{
return (string)$this->id;
}
public function getId(): ?int
{
return $this->id;
}
public function setRemoteId(?string $remoteId = null): self
{
$this->remoteId = $remoteId;
return $this;
}
public function getRemoteId(): ?string
{
return $this->remoteId;
}
public function setQuantity(int $quantity = 0): self
{
$this->quantity = $quantity;
return $this;
}
public function getQuantity(): int
{
return $this->quantity;
}
public function incrementQuantity(): int
{
return $this->quantity++;
}
public function decrementQuantity(): int
{
--$this->quantity;
if ($this->quantity < 0) {
$this->quantity = 0;
}
return $this->quantity;
}
public function setMinimalQuantity(?int $minimalQuantity): self
{
$this->minimalQuantity = $minimalQuantity;
return $this;
}
public function getMinimalQuantity(): ?int
{
return $this->minimalQuantity;
}
public function setOptimalQuantity(?int $optimalQuantity): self
{
$this->optimalQuantity = $optimalQuantity;
return $this;
}
public function getOptimalQuantity(): ?int
{
return $this->optimalQuantity;
}
public function setPrice(float $price): self
{
$this->price = $price;
return $this;
}
public function getPrice(): ?float
{
return $this->price;
}
public function setTaxRate(float $taxRate): self
{
$this->taxRate = $taxRate;
return $this;
}
public function getTaxRate(): ?float
{
if (!$this->taxRate) {
return 0.0;
}
return (float)$this->taxRate;
}
public function getTaxRateMultiplier(): float
{
return $this->getTaxRate() * 0.01;
}
public function setLocation(string $location): self
{
$this->location = $location;
return $this;
}
public function getLocation(): ?string
{
return $this->location;
}
public function setProduct(Product $product = null): self
{
$product?->addQuantity($this);
$this->product = $product;
return $this;
}
public function getProduct(): ?Product
{
return $this->product;
}
public function setDepot(Depot $depot = null): self
{
if($depot instanceof \App\Entity\ECommerce\Depot) {
$this->depot = $depot->addProduct($this);
}
return $this;
}
public function getDepot(): ?Depot
{
return $this->depot;
}
/**
* @ORM\PostLoad()
*/
public function onLoad(): void
{
if ($this->getQuantity() < 0) {
$this->setQuantity(0);
}
}
}