src/Entity/Stocks.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. // use App\Repository\MaterialStockRepository; ❌ @deprecated use StockRepository 👇
  4. use App\Repository\StocksRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use phpDocumentor\Reflection\Types\Boolean;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. use App\Entity\Inventory;
  12. use Doctrine\ORM\Mapping\UniqueConstraint;
  13. /**
  14.  * ⚠️⚠️⚠️⚠️ REPLACE WITH ⚠️⚠️⚠️⚠️⚠️⚠️
  15.  * TODO 👇
  16.  * @deprecated MaterialStockRepository replace with StockRepository
  17.  *
  18.  * ORM\Entity(repositoryClass=MaterialStockRepository::class) ❌ use 👇
  19.  * @ORM\Entity(repositoryClass=StocksRepository::class)
  20.  * UniqueConstraint(name="unique_stock_item", columns={"location_id", "supplier_id", "stock_item_id"})
  21.  * @UniqueEntity(
  22.  *     fields={"location_id", "supplied_product_id"},
  23.  *     message="This item already exists in this location"
  24.  *     )
  25.  * @ORM\Table(name="stocks", uniqueConstraints={
  26.  *          @UniqueConstraint(
  27.  *              name="unique_stock_item",
  28.  *              columns={"location_id", "supplied_product_id"}
  29.  *     )
  30.  *     })
  31.  */
  32. class Stocks
  33. {
  34.     /**
  35.      * @ORM\Id
  36.      * @ORM\GeneratedValue
  37.      * @ORM\Column(type="integer")
  38.      * @Groups({
  39.      *     "stock.core", "stock@core"
  40.      * })
  41.      */
  42.     private $id;
  43.     /**
  44.      * TODO 👇
  45.      * @deprecated use this inside StockTransactions ??? use warehouse !!!
  46.      * @ORM\ManyToOne(targetEntity=Locations::class, inversedBy="stocks")
  47.      * @Groups({
  48.      *      "stock.location",
  49.      *      "stock:location",
  50.      *     "stock@location"
  51.      *  })
  52.      */
  53.     private $location;
  54.     /**
  55.      * @ORM\Column(type="string", length=255, nullable=true)
  56.      * @Groups({
  57.      *      "stock.core", "stock@core"
  58.      *  })
  59.      */
  60.     private $description;
  61.     /**
  62.      * @ORM\Column(type="string", length=255, nullable=true)
  63.      * @Groups({
  64.      *      "stock.core", "stock@core"
  65.      *  })
  66.      */
  67.     private $notes;
  68.     /**
  69.      * @ORM\OneToMany(targetEntity=StockTransactions::class, mappedBy="stock", orphanRemoval=true, cascade={"persist", "remove"})
  70.      * @Groups({
  71.      *       "stock.transactions", "stock@transactions"
  72.      *   })
  73.      */
  74.     private $stock_transactions;
  75.     /**
  76.      * Alboslute need
  77.      * deprecated use SupplierProducts deprecated denilmis ama kesin lazim olacak
  78.      * @ORM\ManyToOne(targetEntity=Suppliers::class, inversedBy="stocks")
  79.      * @Groups({
  80.      *      "stock@supplier"
  81.      *  })
  82.      */
  83.     private $supplier;
  84.     /**
  85.      * TODO Ters iliskli olabilir Burayi cok iyi incele
  86.      * @see Stocks lar ile StockItem arasindaki iliski !!!
  87.      * @ORM\ManyToOne(targetEntity=StockItems::class, inversedBy="stocks")
  88.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  89.      * @Groups({
  90.      *       "stock.item",
  91.      *     "stock:stock_item",
  92.      *     "stock@stock_item"
  93.      *   })
  94.      */
  95.     private $stock_item;
  96.     /**
  97.      * @deprecated use SupplierProducts
  98.      * ORM\Column(type="string", length=255, nullable=true)
  99.      * Groups({"dept_stock.core"})
  100.      */
  101.     private $ean;
  102.     /**
  103.      * ⚠️️️⚠️️️⚠️️️⚠️️️⚠️️️⚠️️️⚠️️️⚠️️️⚠️️️ READ ME ⚠️️️⚠️️️⚠️️️⚠️️️⚠️️️⚠️️️⚠️️️⚠️️️⚠️️️⚠️️️️
  104.      * StockItem genelinde yapılan toplam hesaplamadan farklı olarak,
  105.      * bu alan belirli bir Stock (örneğin bir tedarikçiye veya lokasyona bağlı)
  106.      * için yapılan mevcut stok miktarını temsil eder.
  107.      *
  108.      * Örnek: Civata - Hilti 10 adet, Wirth 28 adet gibi.
  109.      *
  110.      * Bu değer veritabanında fiziksel bir kolon olarak yer almaz.
  111.      * Hesaplama, ilgili Doctrine Subscriber içerisinde dinamik olarak yapılır.
  112.      *
  113.      * @Groups({"stock.core", "stock@core"})
  114.      */
  115.     private $available_stock_quantity;
  116.     /**
  117.      * @deprecated Use "stock@supplier_product" instead.
  118.      * @ORM\ManyToOne(targetEntity=SupplierProducts::class, inversedBy="stocks")
  119.      * @Groups({
  120.      *     "stock.supplier.product",
  121.      *     "stock:suppier_product",
  122.      *
  123.      *     "stock@supplier_product"
  124.      * })
  125.      * @ORM\JoinColumn(onDelete="CASCADE")
  126.      *
  127.      */
  128.     private $supplied_product;
  129.     /**
  130.      * @ORM\Column(type="float", nullable=true)
  131.      * @Groups({
  132.      *      "stock.core", "stock@core"
  133.      *  })
  134.      */
  135.     private $min_stock_quantity;
  136.     /**
  137.      * @ORM\Column(type="string", length=64, nullable=true)
  138.      * @Groups({"stock.core", "stock@core"})
  139.      */
  140.     private $bin_number;
  141.     /**
  142.      * @ORM\Column(type="string", length=64, nullable=true)
  143.      * @Groups({"stock.core", "stock@core"})
  144.      */
  145.     private $rack;
  146.     /**
  147.      * @ORM\OneToMany(targetEntity=PurchaseRequestPositions::class, mappedBy="stock")
  148.      * @Groups({"stock:purchase.request.position"})
  149.      */
  150.     private $purchase_request_positions;
  151.     /**
  152.      * Veritabanında fiziksel bir kolon değildir.
  153.      * Değerinin hesaplanma strategisi
  154.      *
  155.      * Bu Stock urunu alinabilir mi? yani daha once siparis edilmis ve status u approved yada declined'e gore!!
  156.      * @Groups({"stock:purchase_request_not_managed"})
  157.      */
  158.     private $purchase_request_not_managed;
  159.     /**
  160.      * @ORM\ManyToOne(targetEntity=Warehouses::class, inversedBy="stocks")
  161.      * @ORM\JoinColumn(nullable=true) // Daha onceden kayit varsa cakismasin degilse bos olabilir
  162.      * @Groups({
  163.      *     "stock@warehouse"
  164.      * })
  165.      */
  166.     private $warehouse;
  167.     /**
  168.      * @ORM\OneToMany(targetEntity=ProjectOrderExpensePositions::class, mappedBy="stock")
  169.      * @ORM\JoinColumn(onDelete="SET NULL")
  170.      * @Groups({
  171.      *      "stock@expense_positions"
  172.      *  })
  173.      */
  174.     private $project_order_expense_positions;
  175.     /**
  176.      * @ORM\OneToMany(targetEntity=StockIssuePositions::class, mappedBy="stock")
  177.      */
  178.     private $stock_issue_positions;
  179.     public function getPurchaseRequestNotManaged(): ?PurchaseRequestPositions {
  180.         $founded $this->getPurchaseRequestPositions()->filter(function (PurchaseRequestPositions $position) {
  181.             return $position->getApprovedAt() === null && $position->getRejectedAt() === null;
  182.         });
  183.         #dd($founded);
  184.         return $founded->count() ? $founded->first() : null;
  185.     }
  186.     /**
  187.      * Veritabanında fiziksel bir kolon değildir.
  188.      * Değeri Doctrine Subscriber tarafından dinamik olarak hesaplanır.
  189.      */
  190.     public function getAvailableStockQuantity(): float
  191.     {
  192.         return $this->available_stock_quantity;
  193.     }
  194.     /**
  195.      * Veritabanında fiziksel bir kolon değildir.
  196.      * Değeri Doctrine Subscriber tarafından dinamik olarak hesaplanır.
  197.      */
  198.     public function setAvailableStockQuantity(?float $final_quantity )
  199.     {
  200.         $this->available_stock_quantity $final_quantity ?? 0;
  201.     }
  202.     public function __construct()
  203.     {
  204.         $this->stock_transactions = new ArrayCollection();
  205.         $this->purchase_request_positions = new ArrayCollection();
  206.         $this->project_order_expense_positions = new ArrayCollection();
  207.         $this->stock_issue_positions = new ArrayCollection();
  208.     }
  209.     public function getId(): ?int
  210.     {
  211.         return $this->id;
  212.     }
  213.     public function getLocation(): ?Locations
  214.     {
  215.         return $this->location;
  216.     }
  217.     public function setLocation(?Locations $location): self
  218.     {
  219.         $this->location $location;
  220.         return $this;
  221.     }
  222.     public function getSupplier(): ?Suppliers
  223.     {
  224.         return $this->supplier;
  225.     }
  226.     public function setSupplier(?Suppliers $supplier): self
  227.     {
  228.         $this->supplier $supplier;
  229.         return $this;
  230.     }
  231.     public function getDescription(): ?string
  232.     {
  233.         return $this->description;
  234.     }
  235.     public function setDescription(?string $description): self
  236.     {
  237.         $this->description $description;
  238.         return $this;
  239.     }
  240.     public function getNotes(): ?string
  241.     {
  242.         return $this->notes;
  243.     }
  244.     public function setNotes(?string $notes): self
  245.     {
  246.         $this->notes $notes;
  247.         return $this;
  248.     }
  249.     /**
  250.      * @return Collection<int, StockTransactions>
  251.      */
  252.     public function getStockTransactions(): Collection
  253.     {
  254.         return $this->stock_transactions;
  255.     }
  256.     public function addStockTransaction(StockTransactions $stockTransaction): self
  257.     {
  258.         if (!$this->stock_transactions->contains($stockTransaction)) {
  259.             $this->stock_transactions[] = $stockTransaction;
  260.             $stockTransaction->setStock($this);
  261.         }
  262.         return $this;
  263.     }
  264.     public function removeStockTransaction(StockTransactions $stockTransaction): self
  265.     {
  266.         if ($this->stock_transactions->removeElement($stockTransaction)) {
  267.             // set the owning side to null (unless already changed)
  268.             if ($stockTransaction->getStock() === $this) {
  269.                 $stockTransaction->setStock(null);
  270.             }
  271.         }
  272.         return $this;
  273.     }
  274.     public function getStockItem(): ?StockItems
  275.     {
  276.         return $this->stock_item;
  277.     }
  278.     public function setStockItem(?StockItems $stock_item): self
  279.     {
  280.         $this->stock_item $stock_item;
  281.         return $this;
  282.     }
  283.     public function getEan(): ?string
  284.     {
  285.         return $this->ean;
  286.     }
  287.     public function setEan(?string $ean): self
  288.     {
  289.         $this->ean $ean;
  290.         return $this;
  291.     }
  292.     public function getSuppliedProduct(): ?SupplierProducts
  293.     {
  294.         return $this->supplied_product;
  295.     }
  296.     public function setSuppliedProduct(?SupplierProducts $supplied_product): self
  297.     {
  298.         $this->supplied_product $supplied_product;
  299.         return $this;
  300.     }
  301.     public function getMinStockQuantity(): ?float
  302.     {
  303.         return $this->min_stock_quantity;
  304.     }
  305.     public function setMinStockQuantity(?float $min_stock_quantity): self
  306.     {
  307.         $this->min_stock_quantity $min_stock_quantity;
  308.         return $this;
  309.     }
  310.     public function getBinNumber(): ?string
  311.     {
  312.         return $this->bin_number;
  313.     }
  314.     public function setBinNumber(?string $bin_number): self
  315.     {
  316.         $this->bin_number $bin_number;
  317.         return $this;
  318.     }
  319.     public function getRack(): ?string
  320.     {
  321.         return $this->rack;
  322.     }
  323.     public function setRack(?string $rack): self
  324.     {
  325.         $this->rack $rack;
  326.         return $this;
  327.     }
  328.     /**
  329.      * @return Collection<int, PurchaseRequest>
  330.      */
  331.     public function getPurchaseRequestPositions(): Collection
  332.     {
  333.         return $this->purchase_request_positions;
  334.     }
  335.     public function addPurchaseRequest(PurchaseRequest $purchaseRequest): self
  336.     {
  337.         if (!$this->purchase_request_positions->contains($purchaseRequest)) {
  338.             $this->purchase_request_positions[] = $purchaseRequest;
  339.             $purchaseRequest->setStock($this);
  340.         }
  341.         return $this;
  342.     }
  343.     public function removePurchaseRequest(PurchaseRequest $purchaseRequest): self
  344.     {
  345.         if ($this->purchase_request_positions->removeElement($purchaseRequest)) {
  346.             // set the owning side to null (unless already changed)
  347.             if ($purchaseRequest->getStock() === $this) {
  348.                 $purchaseRequest->setStock(null);
  349.             }
  350.         }
  351.         return $this;
  352.     }
  353.     public function getWarehouse(): ?Warehouses
  354.     {
  355.         return $this->warehouse;
  356.     }
  357.     public function setWarehouse(?Warehouses $warehouse): self
  358.     {
  359.         $this->warehouse $warehouse;
  360.         return $this;
  361.     }
  362.     /**
  363.      * @return Collection<int, ProjectOrderExpensePositions>
  364.      */
  365.     public function getProjectOrderExpensePositions(): Collection
  366.     {
  367.         return $this->project_order_expense_positions;
  368.     }
  369.     public function addProjectOrderExpensePosition(ProjectOrderExpensePositions $projectOrderExpensePosition): self
  370.     {
  371.         if (!$this->project_order_expense_positions->contains($projectOrderExpensePosition)) {
  372.             $this->project_order_expense_positions[] = $projectOrderExpensePosition;
  373.             $projectOrderExpensePosition->setStock($this);
  374.         }
  375.         return $this;
  376.     }
  377.     public function removeProjectOrderExpensePosition(ProjectOrderExpensePositions $projectOrderExpensePosition): self
  378.     {
  379.         if ($this->project_order_expense_positions->removeElement($projectOrderExpensePosition)) {
  380.             // set the owning side to null (unless already changed)
  381.             if ($projectOrderExpensePosition->getStock() === $this) {
  382.                 $projectOrderExpensePosition->setStock(null);
  383.             }
  384.         }
  385.         return $this;
  386.     }
  387.     /**
  388.      * @return Collection<int, StockIssuePositions>
  389.      */
  390.     public function getStockIssuePositions(): Collection
  391.     {
  392.         return $this->stock_issue_positions;
  393.     }
  394.     public function addStockIssuePosition(StockIssuePositions $stockIssuePosition): self
  395.     {
  396.         if (!$this->stock_issue_positions->contains($stockIssuePosition)) {
  397.             $this->stock_issue_positions[] = $stockIssuePosition;
  398.             $stockIssuePosition->setStock($this);
  399.         }
  400.         return $this;
  401.     }
  402.     public function removeStockIssuePosition(StockIssuePositions $stockIssuePosition): self
  403.     {
  404.         if ($this->stock_issue_positions->removeElement($stockIssuePosition)) {
  405.             // set the owning side to null (unless already changed)
  406.             if ($stockIssuePosition->getStock() === $this) {
  407.                 $stockIssuePosition->setStock(null);
  408.             }
  409.         }
  410.         return $this;
  411.     }
  412. }