src/Entity/Stock.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\StockRepository;
  4. use DateTime;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. /**
  10.  * @ORM\Entity(repositoryClass=StockRepository::class)
  11.  */
  12. class Stock
  13. {
  14.     /**
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     private $id;
  20.     /**
  21.      * @ORM\ManyToOne(targetEntity=Shop::class, inversedBy="stocks", cascade={"persist"})
  22.      * @ORM\JoinColumn(nullable=false)
  23.      */
  24.     private $shop;
  25.     /**
  26.      * @ORM\Column(type="integer", nullable=true)
  27.      */
  28.     private $rank;
  29.     /**
  30.      * @ORM\Column(type="integer", nullable=true)
  31.      */
  32.     private $qty;
  33.     /**
  34.      * @ORM\Column(type="integer", nullable=true)
  35.      */
  36.     private $price;
  37.     /**
  38.      * @ORM\Column(type="string", length=64)
  39.      */
  40.     private $grade;
  41.     /**
  42.      * @ORM\ManyToOne(targetEntity=Model::class, inversedBy="stocks")
  43.      */
  44.     private $model;
  45.     /**
  46.      * @ORM\ManyToOne(targetEntity=Color::class, inversedBy="stocks")
  47.      */
  48.     private $color;
  49.     /**
  50.      * @ORM\OneToMany(targetEntity=Cart::class, mappedBy="stock")
  51.      */
  52.     private $carts;
  53.     /**
  54.      * @ORM\Column(type="string", length=128)
  55.      */
  56.     private $sourceGrade;
  57.     /**
  58.      * @ORM\Column(type="integer", nullable=true)
  59.      */
  60.     private $publicPrice;
  61.     /**
  62.      * @ORM\Column(type="boolean", nullable=true)
  63.      */
  64.     private $enabled;
  65.     /**
  66.      * @ORM\Column(type="datetime", nullable=true)
  67.      */
  68.     private $updated;
  69.     /**
  70.      * @ORM\Column(type="boolean", nullable=true)
  71.      */
  72.     private $override;
  73.     /**
  74.      * @ORM\ManyToMany(targetEntity=Option::class, mappedBy="stock", cascade={"persist"})
  75.      */
  76.     private $options;
  77.     /**
  78.      * @ORM\Column(type="integer", nullable=true)
  79.      */
  80.     private $optionPrice;
  81.     /**
  82.      * @ORM\ManyToOne(targetEntity=Product::class, inversedBy="stocks")
  83.      */
  84.     private $product;
  85.     private $fullName;
  86.     public function __construct()
  87.     {
  88.         $this->carts = new ArrayCollection();
  89.         $this->options = new ArrayCollection();
  90.     }
  91.     public function __toString() {
  92.         return $this->model->getName()."-".$this->color->getName()."-".$this->grade;
  93.     }
  94.     public function fullName() {
  95.         return $this->getShop()."-".$this->model->getManufacturer()."-".$this->model->getName()."-".$this->color->getName()."-".$this->grade;
  96.     }
  97.     public function getId(): ?int
  98.     {
  99.         return $this->id;
  100.     }
  101.     public function getShop(): ?Shop
  102.     {
  103.         return $this->shop;
  104.     }
  105.     public function setShop(?Shop $shop): self
  106.     {
  107.         $this->shop $shop;
  108.         return $this;
  109.     }
  110.     public function getRank(): ?int
  111.     {
  112.         return $this->rank;
  113.     }
  114.     public function setRank(?int $rank): self
  115.     {
  116.         $this->rank $rank;
  117.         return $this;
  118.     }
  119.     public function getQty(): ?int
  120.     {
  121.         return $this->qty;
  122.     }
  123.     public function setQty(?int $qty): self
  124.     {
  125.         $this->qty $qty;
  126.         return $this;
  127.     }
  128.     public function getPrice(): ?int
  129.     {
  130.         return $this->price;
  131.     }
  132.     public function setPrice(?int $price): self
  133.     {
  134.         $this->price $price;
  135.         return $this;
  136.     }
  137.     public function getGrade(): ?string
  138.     {
  139.         return $this->grade;
  140.     }
  141.     public function setGrade(string $grade): self
  142.     {
  143.         $this->grade $grade;
  144.         return $this;
  145.     }
  146.     public function getModel(): ?Model
  147.     {
  148.         return $this->model;
  149.     }
  150.     public function setModel(?Model $model): self
  151.     {
  152.         $this->model $model;
  153.         return $this;
  154.     }
  155.     public function getColor(): ?Color
  156.     {
  157.         return $this->color;
  158.     }
  159.     public function setColor(?Color $color): self
  160.     {
  161.         $this->color $color;
  162.         return $this;
  163.     }
  164.     public function getUserPrice(): ?int
  165.     {
  166.         $price=$this->getPrice();
  167.         switch($this->getShop()->getId()) {
  168.             case '3':
  169.                 switch (true) {
  170.                     case  ($price 20000):
  171.                         $price $price 1.1;
  172.                         break;
  173.                     case  ($price 40000):
  174.                         $price $price 1.09;
  175.                         break;
  176.                     case  ($price 60000):
  177.                         $price $price 1.08;
  178.                         break;
  179.                     default:
  180.                         $price $price 1.075;
  181.                 }
  182.                 break;
  183.             case "5"://envie
  184.                 $priceTTC=$price*1.2;
  185.                 if($this->getModel()->getCategory()->getId()==4) { // accessoires
  186.                     $price $price 1.2;
  187.                 }
  188.                 else {
  189.                     switch (true) {
  190.                         case  ($priceTTC 25000):
  191.                             $price $price 1.1;
  192.                             break;
  193.                         case  ($priceTTC 50000):
  194.                             $price $price 1.08;
  195.                             break;
  196.                         default:
  197.                             $price $price 1.06;
  198.                     }
  199.                 }
  200.                 break;
  201.         }
  202.        // $price=($price/100);
  203.         return (int)($price/100)*100;
  204.     }
  205.     /**
  206.      * @return Collection<int, Cart>
  207.      */
  208.     public function getCarts(): Collection
  209.     {
  210.         return $this->carts;
  211.     }
  212.     public function addCart(Cart $cart): self
  213.     {
  214.         if (!$this->carts->contains($cart)) {
  215.             $this->carts[] = $cart;
  216.             $cart->setStock($this);
  217.         }
  218.         return $this;
  219.     }
  220.     public function removeCart(Cart $cart): self
  221.     {
  222.         if ($this->carts->removeElement($cart)) {
  223.             // set the owning side to null (unless already changed)
  224.             if ($cart->getStock() === $this) {
  225.                 $cart->setStock(null);
  226.             }
  227.         }
  228.         return $this;
  229.     }
  230.     public function getSourceGrade(): ?string
  231.     {
  232.         return $this->sourceGrade;
  233.     }
  234.     public function setSourceGrade(string $sourceGrade): self
  235.     {
  236.         $this->sourceGrade $sourceGrade;
  237.         return $this;
  238.     }
  239.     public function getPublicPrice(): ?int
  240.     {
  241.         $price=$this->getUserPrice();
  242.         switch($this->getShop()->getId()) {
  243.             case '3':
  244.                 switch (true) {
  245.                     case  ($price 20000):
  246.                         $price $price 1.1;
  247.                         break;
  248.                     case  ($price 40000):
  249.                         $price $price 1.09;
  250.                         break;
  251.                     case  ($price 60000):
  252.                         $price $price 1.08;
  253.                         break;
  254.                     default:
  255.                         $price $price 1.075;
  256.                 }
  257.                 break;
  258.         }
  259.         //$price=($price/100);
  260.         //$price=$price * 1.2;
  261.         return (int)($price/100)*100;
  262.     }
  263.     public function setPublicPrice(?int $publicPrice): self
  264.     {
  265.         $this->publicPrice $publicPrice;
  266.         return $this;
  267.     }
  268.     public function getUpdated() {
  269.         return $this->updated;
  270.     }
  271.     public function setUpdated($updated): self {
  272.         $this->updated = new DateTime("now");
  273.         return $this;
  274.     }
  275.     public function isEnabled(): ?bool
  276.     {
  277.         return $this->enabled;
  278.     }
  279.     public function setEnabled(?bool $enabled): self
  280.     {
  281.         $this->enabled $enabled;
  282.         return $this;
  283.     }
  284.     /**
  285.      * @return Collection<int, Option>
  286.      */
  287.     public function getOptions(): Collection
  288.     {
  289.         return $this->options;
  290.     }
  291.     public function addOption(Option $option): static
  292.     {
  293.         if (!$this->options->contains($option)) {
  294.             $this->options->add($option);
  295.             $option->addStock($this);
  296.         }
  297.         return $this;
  298.     }
  299.     public function removeOption(Option $option): static
  300.     {
  301.         if ($this->options->removeElement($option)) {
  302.             $option->removeStock($this);
  303.         }
  304.         return $this;
  305.     }
  306.     public function getOptionPrice(): ?int
  307.     {
  308.         return $this->optionPrice;
  309.     }
  310.     public function setOptionPrice(int $optionPrice): static
  311.     {
  312.         $this->optionPrice $optionPrice;
  313.         return $this;
  314.     }
  315.     public function isOverride(): ?bool
  316.     {
  317.         return $this->override;
  318.     }
  319.     public function setOverride(?bool $override): static
  320.     {
  321.         $this->override $override;
  322.         return $this;
  323.     }
  324.     public function getProduct(): ?Product
  325.     {
  326.         return $this->product;
  327.     }
  328.     public function setProduct(?Product $product): static
  329.     {
  330.         $this->product $product;
  331.         return $this;
  332.     }
  333. }