src/Entity/SupplierItem.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7.  * @ORM\Table(name="suppliers__items",
  8.  *      uniqueConstraints={
  9.  *           @ORM\UniqueConstraint(columns={"supplier_id", "product_id"}),
  10.  *       })
  11.  * @ORM\Entity(repositoryClass="App\Repository\SupplierItemRepository")
  12.  */
  13. class SupplierItem
  14. {
  15.     use IdTrait;
  16.     use UpdatedAtTrait;
  17.     /**
  18.      * @ORM\ManyToOne(targetEntity="Product")
  19.      * @ORM\JoinColumn(name="product_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
  20.      */
  21.     private Product $product;
  22.     /**
  23.      * @ORM\ManyToOne(targetEntity="Supplier")
  24.      * @ORM\JoinColumn(name="supplier_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
  25.      */
  26.     private Supplier $supplier;
  27.     /**
  28.      * @ORM\Column(name="price", type="integer", options={"default":0})
  29.      */
  30.     private int $price 0;
  31.     /**
  32.      * @ORM\Column(name="multiplicity", type="integer", options={"default":1})
  33.      */
  34.     private int $multiplicity 1;
  35.     /**
  36.      * @ORM\Column(name="vendor_id", type="string", nullable=true)
  37.      */
  38.     private ?string $vendorId null;
  39.     /**
  40.      * @var SupplierWarehouseItem[]|Collection
  41.      * @ORM\OneToMany(targetEntity="SupplierWarehouseItem", mappedBy="item")
  42.      */
  43.     private $supplierWarehouseItems;
  44.     public function __construct(Product $productSupplier $supplier)
  45.     {
  46.         $this->product $product;
  47.         $this->supplier $supplier;
  48.         $this->supplierWarehouseItems = new ArrayCollection();
  49.     }
  50.     public function getSupplier(): Supplier
  51.     {
  52.         return $this->supplier;
  53.     }
  54.     public function getProduct(): Product
  55.     {
  56.         return $this->product;
  57.     }
  58.     public function getPrice(): int
  59.     {
  60.         return $this->price;
  61.     }
  62.     public function getVendorId(): ?string
  63.     {
  64.         return $this->vendorId;
  65.     }
  66.     /**
  67.      * @return Collection|SupplierWarehouseItem[]
  68.      */
  69.     public function getSupplierWarehouseItems()
  70.     {
  71.         return $this->supplierWarehouseItems;
  72.     }
  73.     public function calculatePrice(): int
  74.     {
  75.         $supplier $this->getSupplier();
  76.         $supplierMarkup $supplier->getSupplierMarkup();
  77.         $supplierBrandDiscount $supplier->getSupplierBrandDiscount($this->getProduct()->getBrand());
  78.         $price $this->price;
  79.         $price $price * (- ($supplierBrandDiscount $supplierBrandDiscount->getDiscount() : 0) / 10000);
  80.         $price $price * (+ ($supplierMarkup $supplierMarkup->getMarkup() : 0) / 10000);
  81.         $supplierMarkupRangeValue $supplier->getSupplierMarkupRange($price);
  82.         return (int)round($price * (+ ($supplierMarkupRangeValue $supplierMarkupRangeValue->getMarkup() : 0) / 10000));
  83.     }
  84. }