<?php
namespace App\Entity;
use App\Repository\StockRepository;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=StockRepository::class)
*/
class Stock
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=Shop::class, inversedBy="stocks", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
*/
private $shop;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $rank;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $qty;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $price;
/**
* @ORM\Column(type="string", length=64)
*/
private $grade;
/**
* @ORM\ManyToOne(targetEntity=Model::class, inversedBy="stocks")
*/
private $model;
/**
* @ORM\ManyToOne(targetEntity=Color::class, inversedBy="stocks")
*/
private $color;
/**
* @ORM\OneToMany(targetEntity=Cart::class, mappedBy="stock")
*/
private $carts;
/**
* @ORM\Column(type="string", length=128)
*/
private $sourceGrade;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $publicPrice;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $enabled;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updated;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $override;
/**
* @ORM\ManyToMany(targetEntity=Option::class, mappedBy="stock", cascade={"persist"})
*/
private $options;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $optionPrice;
/**
* @ORM\ManyToOne(targetEntity=Product::class, inversedBy="stocks")
*/
private $product;
private $fullName;
public function __construct()
{
$this->carts = new ArrayCollection();
$this->options = new ArrayCollection();
}
public function __toString() {
return $this->model->getName()."-".$this->color->getName()."-".$this->grade;
}
public function fullName() {
return $this->getShop()."-".$this->model->getManufacturer()."-".$this->model->getName()."-".$this->color->getName()."-".$this->grade;
}
public function getId(): ?int
{
return $this->id;
}
public function getShop(): ?Shop
{
return $this->shop;
}
public function setShop(?Shop $shop): self
{
$this->shop = $shop;
return $this;
}
public function getRank(): ?int
{
return $this->rank;
}
public function setRank(?int $rank): self
{
$this->rank = $rank;
return $this;
}
public function getQty(): ?int
{
return $this->qty;
}
public function setQty(?int $qty): self
{
$this->qty = $qty;
return $this;
}
public function getPrice(): ?int
{
return $this->price;
}
public function setPrice(?int $price): self
{
$this->price = $price;
return $this;
}
public function getGrade(): ?string
{
return $this->grade;
}
public function setGrade(string $grade): self
{
$this->grade = $grade;
return $this;
}
public function getModel(): ?Model
{
return $this->model;
}
public function setModel(?Model $model): self
{
$this->model = $model;
return $this;
}
public function getColor(): ?Color
{
return $this->color;
}
public function setColor(?Color $color): self
{
$this->color = $color;
return $this;
}
public function getUserPrice(): ?int
{
$price=$this->getPrice();
switch($this->getShop()->getId()) {
case '3':
switch (true) {
case ($price < 20000):
$price = $price * 1.1;
break;
case ($price < 40000):
$price = $price * 1.09;
break;
case ($price < 60000):
$price = $price * 1.08;
break;
default:
$price = $price * 1.075;
}
break;
case "5"://envie
$priceTTC=$price*1.2;
if($this->getModel()->getCategory()->getId()==4) { // accessoires
$price = $price * 1.2;
}
else {
switch (true) {
case ($priceTTC < 25000):
$price = $price * 1.1;
break;
case ($priceTTC < 50000):
$price = $price * 1.08;
break;
default:
$price = $price * 1.06;
}
}
break;
}
// $price=($price/100);
return (int)($price/100)*100;
}
/**
* @return Collection<int, Cart>
*/
public function getCarts(): Collection
{
return $this->carts;
}
public function addCart(Cart $cart): self
{
if (!$this->carts->contains($cart)) {
$this->carts[] = $cart;
$cart->setStock($this);
}
return $this;
}
public function removeCart(Cart $cart): self
{
if ($this->carts->removeElement($cart)) {
// set the owning side to null (unless already changed)
if ($cart->getStock() === $this) {
$cart->setStock(null);
}
}
return $this;
}
public function getSourceGrade(): ?string
{
return $this->sourceGrade;
}
public function setSourceGrade(string $sourceGrade): self
{
$this->sourceGrade = $sourceGrade;
return $this;
}
public function getPublicPrice(): ?int
{
$price=$this->getUserPrice();
switch($this->getShop()->getId()) {
case '3':
switch (true) {
case ($price < 20000):
$price = $price * 1.1;
break;
case ($price < 40000):
$price = $price * 1.09;
break;
case ($price < 60000):
$price = $price * 1.08;
break;
default:
$price = $price * 1.075;
}
break;
}
//$price=($price/100);
//$price=$price * 1.2;
return (int)($price/100)*100;
}
public function setPublicPrice(?int $publicPrice): self
{
$this->publicPrice = $publicPrice;
return $this;
}
public function getUpdated() {
return $this->updated;
}
public function setUpdated($updated): self {
$this->updated = new DateTime("now");
return $this;
}
public function isEnabled(): ?bool
{
return $this->enabled;
}
public function setEnabled(?bool $enabled): self
{
$this->enabled = $enabled;
return $this;
}
/**
* @return Collection<int, Option>
*/
public function getOptions(): Collection
{
return $this->options;
}
public function addOption(Option $option): static
{
if (!$this->options->contains($option)) {
$this->options->add($option);
$option->addStock($this);
}
return $this;
}
public function removeOption(Option $option): static
{
if ($this->options->removeElement($option)) {
$option->removeStock($this);
}
return $this;
}
public function getOptionPrice(): ?int
{
return $this->optionPrice;
}
public function setOptionPrice(int $optionPrice): static
{
$this->optionPrice = $optionPrice;
return $this;
}
public function isOverride(): ?bool
{
return $this->override;
}
public function setOverride(?bool $override): static
{
$this->override = $override;
return $this;
}
public function getProduct(): ?Product
{
return $this->product;
}
public function setProduct(?Product $product): static
{
$this->product = $product;
return $this;
}
}