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.      * @Groups({
  170.      *      "stock@expense_positions"
  171.      *  })
  172.      */
  173.     private $project_order_expense_positions;
  174.     /**
  175.      * @ORM\OneToMany(targetEntity=StockIssuePositions::class, mappedBy="stock")
  176.      */
  177.     private $stock_issue_positions;
  178.     public function getPurchaseRequestNotManaged(): ?PurchaseRequestPositions {
  179.         $founded $this->getPurchaseRequestPositions()->filter(function (PurchaseRequestPositions $position) {
  180.             return $position->getApprovedAt() === null && $position->getRejectedAt() === null;
  181.         });
  182.         #dd($founded);
  183.         return $founded->count() ? $founded->first() : null;
  184.     }
  185.     /**
  186.      * Veritabanında fiziksel bir kolon değildir.
  187.      * Değeri Doctrine Subscriber tarafından dinamik olarak hesaplanır.
  188.      */
  189.     public function getAvailableStockQuantity(): float
  190.     {
  191.         return $this->available_stock_quantity;
  192.     }
  193.     /**
  194.      * Veritabanında fiziksel bir kolon değildir.
  195.      * Değeri Doctrine Subscriber tarafından dinamik olarak hesaplanır.
  196.      */
  197.     public function setAvailableStockQuantity(?float $final_quantity )
  198.     {
  199.         $this->available_stock_quantity $final_quantity ?? 0;
  200.     }
  201.     public function __construct()
  202.     {
  203.         $this->stock_transactions = new ArrayCollection();
  204.         $this->purchase_request_positions = new ArrayCollection();
  205.         $this->project_order_expense_positions = new ArrayCollection();
  206.         $this->stock_issue_positions = new ArrayCollection();
  207.     }
  208.     public function getId(): ?int
  209.     {
  210.         return $this->id;
  211.     }
  212.     public function getLocation(): ?Locations
  213.     {
  214.         return $this->location;
  215.     }
  216.     public function setLocation(?Locations $location): self
  217.     {
  218.         $this->location $location;
  219.         return $this;
  220.     }
  221.     public function getSupplier(): ?Suppliers
  222.     {
  223.         return $this->supplier;
  224.     }
  225.     public function setSupplier(?Suppliers $supplier): self
  226.     {
  227.         $this->supplier $supplier;
  228.         return $this;
  229.     }
  230.     public function getDescription(): ?string
  231.     {
  232.         return $this->description;
  233.     }
  234.     public function setDescription(?string $description): self
  235.     {
  236.         $this->description $description;
  237.         return $this;
  238.     }
  239.     public function getNotes(): ?string
  240.     {
  241.         return $this->notes;
  242.     }
  243.     public function setNotes(?string $notes): self
  244.     {
  245.         $this->notes $notes;
  246.         return $this;
  247.     }
  248.     /**
  249.      * @return Collection<int, StockTransactions>
  250.      */
  251.     public function getStockTransactions(): Collection
  252.     {
  253.         return $this->stock_transactions;
  254.     }
  255.     public function addStockTransaction(StockTransactions $stockTransaction): self
  256.     {
  257.         if (!$this->stock_transactions->contains($stockTransaction)) {
  258.             $this->stock_transactions[] = $stockTransaction;
  259.             $stockTransaction->setStock($this);
  260.         }
  261.         return $this;
  262.     }
  263.     public function removeStockTransaction(StockTransactions $stockTransaction): self
  264.     {
  265.         if ($this->stock_transactions->removeElement($stockTransaction)) {
  266.             // set the owning side to null (unless already changed)
  267.             if ($stockTransaction->getStock() === $this) {
  268.                 $stockTransaction->setStock(null);
  269.             }
  270.         }
  271.         return $this;
  272.     }
  273.     public function getStockItem(): ?StockItems
  274.     {
  275.         return $this->stock_item;
  276.     }
  277.     public function setStockItem(?StockItems $stock_item): self
  278.     {
  279.         $this->stock_item $stock_item;
  280.         return $this;
  281.     }
  282.     public function getEan(): ?string
  283.     {
  284.         return $this->ean;
  285.     }
  286.     public function setEan(?string $ean): self
  287.     {
  288.         $this->ean $ean;
  289.         return $this;
  290.     }
  291.     public function getSuppliedProduct(): ?SupplierProducts
  292.     {
  293.         return $this->supplied_product;
  294.     }
  295.     public function setSuppliedProduct(?SupplierProducts $supplied_product): self
  296.     {
  297.         $this->supplied_product $supplied_product;
  298.         return $this;
  299.     }
  300.     public function getMinStockQuantity(): ?float
  301.     {
  302.         return $this->min_stock_quantity;
  303.     }
  304.     public function setMinStockQuantity(?float $min_stock_quantity): self
  305.     {
  306.         $this->min_stock_quantity $min_stock_quantity;
  307.         return $this;
  308.     }
  309.     public function getBinNumber(): ?string
  310.     {
  311.         return $this->bin_number;
  312.     }
  313.     public function setBinNumber(?string $bin_number): self
  314.     {
  315.         $this->bin_number $bin_number;
  316.         return $this;
  317.     }
  318.     public function getRack(): ?string
  319.     {
  320.         return $this->rack;
  321.     }
  322.     public function setRack(?string $rack): self
  323.     {
  324.         $this->rack $rack;
  325.         return $this;
  326.     }
  327.     /**
  328.      * @return Collection<int, PurchaseRequest>
  329.      */
  330.     public function getPurchaseRequestPositions(): Collection
  331.     {
  332.         return $this->purchase_request_positions;
  333.     }
  334.     public function addPurchaseRequest(PurchaseRequest $purchaseRequest): self
  335.     {
  336.         if (!$this->purchase_request_positions->contains($purchaseRequest)) {
  337.             $this->purchase_request_positions[] = $purchaseRequest;
  338.             $purchaseRequest->setStock($this);
  339.         }
  340.         return $this;
  341.     }
  342.     public function removePurchaseRequest(PurchaseRequest $purchaseRequest): self
  343.     {
  344.         if ($this->purchase_request_positions->removeElement($purchaseRequest)) {
  345.             // set the owning side to null (unless already changed)
  346.             if ($purchaseRequest->getStock() === $this) {
  347.                 $purchaseRequest->setStock(null);
  348.             }
  349.         }
  350.         return $this;
  351.     }
  352.     public function getWarehouse(): ?Warehouses
  353.     {
  354.         return $this->warehouse;
  355.     }
  356.     public function setWarehouse(?Warehouses $warehouse): self
  357.     {
  358.         $this->warehouse $warehouse;
  359.         return $this;
  360.     }
  361.     /**
  362.      * @return Collection<int, ProjectOrderExpensePositions>
  363.      */
  364.     public function getProjectOrderExpensePositions(): Collection
  365.     {
  366.         return $this->project_order_expense_positions;
  367.     }
  368.     public function addProjectOrderExpensePosition(ProjectOrderExpensePositions $projectOrderExpensePosition): self
  369.     {
  370.         if (!$this->project_order_expense_positions->contains($projectOrderExpensePosition)) {
  371.             $this->project_order_expense_positions[] = $projectOrderExpensePosition;
  372.             $projectOrderExpensePosition->setStock($this);
  373.         }
  374.         return $this;
  375.     }
  376.     public function removeProjectOrderExpensePosition(ProjectOrderExpensePositions $projectOrderExpensePosition): self
  377.     {
  378.         if ($this->project_order_expense_positions->removeElement($projectOrderExpensePosition)) {
  379.             // set the owning side to null (unless already changed)
  380.             if ($projectOrderExpensePosition->getStock() === $this) {
  381.                 $projectOrderExpensePosition->setStock(null);
  382.             }
  383.         }
  384.         return $this;
  385.     }
  386.     /**
  387.      * @return Collection<int, StockIssuePositions>
  388.      */
  389.     public function getStockIssuePositions(): Collection
  390.     {
  391.         return $this->stock_issue_positions;
  392.     }
  393.     public function addStockIssuePosition(StockIssuePositions $stockIssuePosition): self
  394.     {
  395.         if (!$this->stock_issue_positions->contains($stockIssuePosition)) {
  396.             $this->stock_issue_positions[] = $stockIssuePosition;
  397.             $stockIssuePosition->setStock($this);
  398.         }
  399.         return $this;
  400.     }
  401.     public function removeStockIssuePosition(StockIssuePositions $stockIssuePosition): self
  402.     {
  403.         if ($this->stock_issue_positions->removeElement($stockIssuePosition)) {
  404.             // set the owning side to null (unless already changed)
  405.             if ($stockIssuePosition->getStock() === $this) {
  406.                 $stockIssuePosition->setStock(null);
  407.             }
  408.         }
  409.         return $this;
  410.     }
  411. }