src/Entity/Stock.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\StockRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=StockRepository::class)
  9.  */
  10. class Stock
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="integer", options={"default": 0, "comment": "Quantité physique en stock. La quantité disponible à la vente est qt_stock - qt_reserved"})
  20.      */
  21.     private $qtStock;
  22.     /**
  23.      * @ORM\Column(type="integer")
  24.      */
  25.     private $qtReserved;
  26.     /**
  27.      * @ORM\Column(name="incoming_quantity", type="integer", options={"default": 0, "comment": "Quantite en attente d'arrivage issue des bons d'achat fournisseur"})
  28.      */
  29.     private int $incomingQuantity 0;
  30.     /**
  31.      * @ORM\Column(name="incoming_date_estimated", type="datetime", nullable=true, options={"comment": "Date estimee du prochain arrivage"})
  32.      */
  33.     private ?\DateTimeInterface $incomingDateEstimated null;
  34.     /**
  35.      * @ORM\Column(name="exchange_incoming_quantity", type="integer", options={"default": 0, "comment": "Quantite attendue depuis des bons d echange client acceptes"})
  36.      */
  37.     private int $exchangeIncomingQuantity 0;
  38.     /**
  39.      * @ORM\ManyToOne(targetEntity=Produit::class, inversedBy="stocks")
  40.      */
  41.     private $produit;
  42.     /**
  43.      * @ORM\ManyToOne(targetEntity=ProduitDeclinationValue::class, inversedBy="stocks")
  44.      */
  45.     private $declinationProduit;
  46.     /**
  47.      * @ORM\ManyToOne(targetEntity=Warehouse::class, inversedBy="stocks")
  48.      * @ORM\JoinColumn(name="warehouse_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
  49.      */
  50.     private $warehouse;
  51.     /**
  52.      * @ORM\Column(name="average_unit_cost", type="decimal", precision=12, scale=3, options={"default":"0.000"})
  53.      */
  54.     private string $averageUnitCost '0.000';
  55.     /**
  56.      * @ORM\Column(name="last_purchase_price", type="decimal", precision=12, scale=3, nullable=true)
  57.      */
  58.     private ?string $lastPurchasePrice null;
  59.     /**
  60.      * @ORM\Column(name="valuation_updated_at", type="datetime", nullable=true)
  61.      */
  62.     private ?\DateTimeInterface $valuationUpdatedAt null;
  63.     /**
  64.      * @ORM\OneToMany(targetEntity=Activity::class, mappedBy="stock")
  65.      */
  66.     private $activities;
  67.     public function __construct()
  68.     {
  69.         $this->activities = new ArrayCollection();
  70.     }
  71.     public function getId(): ?int
  72.     {
  73.         return $this->id;
  74.     }
  75.     public function getQtStock(): ?int
  76.     {
  77.         return $this->qtStock;
  78.     }
  79.     public function setQtStock(int $qtStock): self
  80.     {
  81.         $this->qtStock $qtStock;
  82.         return $this;
  83.     }
  84.     public function getQtReserved(): ?int
  85.     {
  86.         return $this->qtReserved;
  87.     }
  88.     public function setQtReserved(int $qtReserved): self
  89.     {
  90.         $this->qtReserved $qtReserved;
  91.         return $this;
  92.     }
  93.     public function getIncomingQuantity(): int
  94.     {
  95.         return (int) $this->incomingQuantity;
  96.     }
  97.     public function setIncomingQuantity(int $incomingQuantity): self
  98.     {
  99.         $this->incomingQuantity max(0, (int) $incomingQuantity);
  100.         return $this;
  101.     }
  102.     public function getIncomingDateEstimated(): ?\DateTimeInterface
  103.     {
  104.         return $this->incomingDateEstimated;
  105.     }
  106.     public function setIncomingDateEstimated(?\DateTimeInterface $incomingDateEstimated): self
  107.     {
  108.         $this->incomingDateEstimated $incomingDateEstimated;
  109.         return $this;
  110.     }
  111.     public function getExchangeIncomingQuantity(): int
  112.     {
  113.         return (int) $this->exchangeIncomingQuantity;
  114.     }
  115.     public function setExchangeIncomingQuantity(int $exchangeIncomingQuantity): self
  116.     {
  117.         $this->exchangeIncomingQuantity max(0, (int) $exchangeIncomingQuantity);
  118.         return $this;
  119.     }
  120.     public function getIncomingRemainingQuantity(): int
  121.     {
  122.         $incoming = (int) $this->getIncomingQuantity();
  123.         if ($incoming <= 0) {
  124.             return 0;
  125.         }
  126.         $realAvailable = (int) $this->getQtStock() - (int) $this->getQtReserved();
  127.         if ($realAvailable 0) {
  128.             return $incoming;
  129.         }
  130.         $absorbedByShortage max(0$realAvailable);
  131.         return max(0$incoming $absorbedByShortage);
  132.     }
  133.     public function getAvailableQuantityForWebsite(): int
  134.     {
  135.         return max(0, ((int) $this->getQtStock() - (int) $this->getQtReserved()) + (int) $this->getIncomingQuantity());
  136.     }
  137.     public function getProduit(): ?Produit
  138.     {
  139.         return $this->produit;
  140.     }
  141.     public function setProduit(?Produit $produit): self
  142.     {
  143.         $this->produit $produit;
  144.         return $this;
  145.     }
  146.     public function getDeclinationProduit(): ?ProduitDeclinationValue
  147.     {
  148.         return $this->declinationProduit;
  149.     }
  150.     public function setDeclinationProduit(?ProduitDeclinationValue $declinationProduit): self
  151.     {
  152.         $this->declinationProduit $declinationProduit;
  153.         return $this;
  154.     }
  155.     public function getResolvedStorehouseName(): ?string
  156.     {
  157.         return $this->warehouse instanceof Warehouse && $this->warehouse->getName()
  158.             ? (string) $this->warehouse->getName()
  159.             : null;
  160.     }
  161.     public function getWarehouse(): ?Warehouse
  162.     {
  163.         return $this->warehouse;
  164.     }
  165.     public function setWarehouse(?Warehouse $warehouse): self
  166.     {
  167.         $this->warehouse $warehouse;
  168.         return $this;
  169.     }
  170.     public function getAverageUnitCost(): ?float
  171.     {
  172.         return (float) $this->averageUnitCost;
  173.     }
  174.     public function setAverageUnitCost(?float $averageUnitCost): self
  175.     {
  176.         $this->averageUnitCost number_format((float) ($averageUnitCost ?? 0), 3'.''');
  177.         return $this;
  178.     }
  179.     public function getLastPurchasePrice(): ?float
  180.     {
  181.         return $this->lastPurchasePrice !== null ? (float) $this->lastPurchasePrice null;
  182.     }
  183.     public function setLastPurchasePrice(?float $lastPurchasePrice): self
  184.     {
  185.         $this->lastPurchasePrice $lastPurchasePrice !== null
  186.             number_format((float) $lastPurchasePrice3'.''')
  187.             : null;
  188.         return $this;
  189.     }
  190.     public function getValuationUpdatedAt(): ?\DateTimeInterface
  191.     {
  192.         return $this->valuationUpdatedAt;
  193.     }
  194.     public function setValuationUpdatedAt(?\DateTimeInterface $valuationUpdatedAt): self
  195.     {
  196.         $this->valuationUpdatedAt $valuationUpdatedAt;
  197.         return $this;
  198.     }
  199.     /**
  200.      * @return Collection|Activity[]
  201.      */
  202.     public function getActivities(): Collection
  203.     {
  204.         return $this->activities;
  205.     }
  206.     public function addActivity(Activity $activity): self
  207.     {
  208.         if( !$this->activities->contains($activity)) {
  209.             $this->activities[] = $activity;
  210.             $activity->setStock($this);
  211.         }
  212.         return $this;
  213.     }
  214.     public function removeActivity(Activity $activity): self
  215.     {
  216.         if( $this->activities->removeElement($activity)) {
  217.             // set the owning side to null (unless already changed)
  218.             if( $activity->getStock() === $this) {
  219.                 $activity->setStock(null);
  220.             }
  221.         }
  222.         return $this;
  223.     }
  224.     public function __toString() {
  225.         return $this->id;
  226.     }
  227. }