src/Entity/System/ProductStock.php line 14

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\System;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6. * @ORM\Table(
  7. * uniqueConstraints={
  8. *
  9. * @ORM\UniqueConstraint(name="uk_product_product_attribute_reference", columns={"product_id", "product_attribute_id", "reference"})
  10. * }
  11. * )
  12. *
  13. * @ORM\Entity(repositoryClass="App\Repository\System\ProductStockRepository")
  14. */
  15. class ProductStock
  16. {
  17. public const AVAILABLE_STOCK = '0_0';
  18. public const COMING_STOCK = 'X_X';
  19. public const JIT_STOCK = '1_2';
  20. public const JIT_3_5_STOCK = '3_5';
  21. public const JIT_MIN_DAYS = 1;
  22. public const JIT_MAX_DAYS = 2;
  23. public const JIT_3_5_MIN_DAYS = 3;
  24. public const JIT_3_5_MAX_DAYS = 5;
  25. public const IMMEDIATE_STOCK_MIN_DAYS = 0;
  26. public const IMMEDIATE_STOCK_MAX_DAYS = 0;
  27. public const STOCK_WITHOUT_PURCHASE_ID_REFERENCE = '0';
  28. /** Margen de cortesía en días para envíos / texto de plazo (equivalente al antiguo stock entrante). */
  29. public const INCOMING_COURTESY_DAYS = 5;
  30. public const UNLIMITED_STOCK_QUANTITY_FOR_VIRTUAL_PRODUCTS = 500;
  31. public const MIN_PRODUCT_STOCK_PERCENTAGE = 0.6;
  32. /**
  33. * @ORM\Column(type="integer")
  34. *
  35. * @ORM\Id
  36. *
  37. * @ORM\GeneratedValue(strategy="AUTO")
  38. */
  39. protected int $id;
  40. /**
  41. * @ORM\Column(type="string", length=32, nullable=true)
  42. */
  43. protected ?string $reference;
  44. /**
  45. * @ORM\ManyToOne(targetEntity="App\Entity\System\Product", inversedBy="productStocks", cascade={"persist"})
  46. *
  47. * @ORM\JoinColumn(referencedColumnName="id_product", nullable=false)
  48. */
  49. private Product $product;
  50. /**
  51. * @ORM\ManyToOne(targetEntity="ProductAttribute", cascade={"persist"})
  52. *
  53. * @ORM\JoinColumn(referencedColumnName="id_product_attribute")
  54. */
  55. private ?ProductAttribute $productAttribute;
  56. /**
  57. * @ORM\Column(type="integer", nullable=false, options={"default":0})
  58. */
  59. private int $originalQuantity = 0;
  60. /**
  61. * @ORM\Column(type="integer", nullable=false, options={"default":0})
  62. */
  63. private int $quantity = 0;
  64. /**
  65. * @ORM\Column(type="integer", nullable=false, options={"default":0})
  66. */
  67. private int $quantityPurchased = 0;
  68. /**
  69. * @ORM\Column(type="integer")
  70. */
  71. private int $minimumHandlingDays;
  72. /**
  73. * @ORM\Column(type="integer")
  74. */
  75. private int $maximumHandlingDays;
  76. /**
  77. * @ORM\Column(type="datetime")
  78. */
  79. private \DateTime $dateAdd;
  80. /**
  81. * @ORM\Column(type="datetime")
  82. */
  83. private \DateTime $dateUpdate;
  84. /**
  85. * @ORM\Column(type="boolean", nullable=false, options={"default":0})
  86. */
  87. private bool $purchaseAvailable;
  88. /**
  89. * @var Warehouse
  90. *
  91. * @ORM\ManyToOne(targetEntity="App\Entity\System\Warehouse")
  92. *
  93. * @ORM\JoinColumn(name="warehouse_id", referencedColumnName="id", nullable=false, options={"default":1})
  94. */
  95. private $warehouse;
  96. public function __construct()
  97. {
  98. $this->dateAdd = new \DateTime();
  99. $this->dateUpdate = new \DateTime();
  100. $this->purchaseAvailable = false;
  101. }
  102. public function getId(): int
  103. {
  104. return $this->id;
  105. }
  106. public function getReference(): ?string
  107. {
  108. return $this->reference;
  109. }
  110. public function setReference(?string $reference): ProductStock
  111. {
  112. $this->reference = $reference;
  113. return $this;
  114. }
  115. public function getProduct(): Product
  116. {
  117. return $this->product;
  118. }
  119. public function setProduct(Product $product): ProductStock
  120. {
  121. $this->product = $product;
  122. return $this;
  123. }
  124. public function getProductAttribute(): ?ProductAttribute
  125. {
  126. return $this->productAttribute;
  127. }
  128. public function setProductAttribute(?ProductAttribute $productAttribute): ProductStock
  129. {
  130. $this->productAttribute = $productAttribute;
  131. return $this;
  132. }
  133. public function getQuantity(): int
  134. {
  135. return $this->quantity;
  136. }
  137. public function setQuantity(int $quantity): ProductStock
  138. {
  139. $this->quantity = $quantity;
  140. return $this;
  141. }
  142. public function getMinimumHandlingDays(): int
  143. {
  144. return $this->minimumHandlingDays;
  145. }
  146. public function setMinimumHandlingDays(int $minimumHandlingDays): ProductStock
  147. {
  148. $this->minimumHandlingDays = $minimumHandlingDays;
  149. return $this;
  150. }
  151. public function getMaximumHandlingDays(): int
  152. {
  153. return $this->maximumHandlingDays;
  154. }
  155. public function setMaximumHandlingDays(int $maximumHandlingDays): ProductStock
  156. {
  157. $this->maximumHandlingDays = $maximumHandlingDays;
  158. return $this;
  159. }
  160. public function getDateAdd(): \DateTime
  161. {
  162. return $this->dateAdd;
  163. }
  164. public function setDateAdd(\DateTime $dateAdd): ProductStock
  165. {
  166. $this->dateAdd = $dateAdd;
  167. return $this;
  168. }
  169. public function getDateUpdate(): \DateTime
  170. {
  171. return $this->dateUpdate;
  172. }
  173. public function setDateUpdate(\DateTime $dateUpdate): ProductStock
  174. {
  175. $this->dateUpdate = $dateUpdate;
  176. return $this;
  177. }
  178. public function getOriginalQuantity(): int
  179. {
  180. return $this->originalQuantity;
  181. }
  182. public function setOriginalQuantity(int $originalQuantity): ProductStock
  183. {
  184. $this->originalQuantity = $originalQuantity;
  185. return $this;
  186. }
  187. public function getQuantityPurchased(): int
  188. {
  189. return $this->quantityPurchased;
  190. }
  191. public function setQuantityPurchased(int $quantityPurchased): ProductStock
  192. {
  193. $this->quantityPurchased = $quantityPurchased;
  194. return $this;
  195. }
  196. public function getWarehouse(): Warehouse
  197. {
  198. return $this->warehouse;
  199. }
  200. public function setWarehouse(Warehouse $warehouse): void
  201. {
  202. $this->warehouse = $warehouse;
  203. }
  204. public function isPurchaseAvailable(): bool
  205. {
  206. return $this->purchaseAvailable;
  207. }
  208. public function setPurchaseAvailable(bool $purchaseAvailable): ProductStock
  209. {
  210. $this->purchaseAvailable = $purchaseAvailable;
  211. return $this;
  212. }
  213. public function getEstimatedFutureDateNext(): \DateTimeImmutable
  214. {
  215. $days = max(0, $this->maximumHandlingDays);
  216. return \DateTimeImmutable::createFromMutable($this->dateUpdate)
  217. ->modify(sprintf('+%d days', $days));
  218. }
  219. public function getEstimatedFutureAvailableDateNext(): \DateTimeImmutable
  220. {
  221. $days = max(0, $this->minimumHandlingDays);
  222. return \DateTimeImmutable::createFromMutable($this->dateUpdate)
  223. ->modify(sprintf('+%d days', $days));
  224. }
  225. }