src/Entity/OrderProduct.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\OrderProductRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use JsonSerializable;
  9. #[ORM\Entity(repositoryClass: OrderProductRepository::class)]
  10. class OrderProduct implements JsonSerializable
  11. {
  12. #[ORM\Id]
  13. #[ORM\GeneratedValue]
  14. #[ORM\Column(type: 'integer')]
  15. private $id;
  16. #[ORM\ManyToOne(targetEntity: Product::class)]
  17. #[ORM\JoinColumn(nullable: false)]
  18. private $product;
  19. #[ORM\Column(type: 'decimal', precision: 10, scale: 3)]
  20. private $price;
  21. #[ORM\Column(type: 'integer')]
  22. private $qty;
  23. #[ORM\ManyToOne(targetEntity: Order::class, inversedBy: 'orderProducts')]
  24. #[ORM\JoinColumn(nullable: false)]
  25. private $orderParent;
  26. #[ORM\Column(type: 'integer', nullable: true)]
  27. private $qtePreCmd;
  28. #[ORM\OneToMany(targetEntity: OrderProductSurface::class, mappedBy: 'orderProduct')]
  29. private $surfaces;
  30. #[ORM\OneToOne(targetEntity: ViewOrderProductSansArbres::class, mappedBy: 'orderProduct', cascade: ['persist', 'remove'])]
  31. private $orderProductSansArbres;
  32. #[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, nullable: true)]
  33. private ?string $tva = null;
  34. public function __construct()
  35. {
  36. $this->surfaces = new ArrayCollection();
  37. }
  38. public function getId(): ?int
  39. {
  40. return $this->id;
  41. }
  42. public function getProduct(): ?Product
  43. {
  44. return $this->product;
  45. }
  46. public function setProduct(?Product $product): self
  47. {
  48. $this->product = $product;
  49. return $this;
  50. }
  51. public function getPrice(): ?string
  52. {
  53. return $this->price;
  54. }
  55. public function setPrice(string $price): self
  56. {
  57. $this->price = $price;
  58. return $this;
  59. }
  60. public function getQty(): ?int
  61. {
  62. return $this->qty;
  63. }
  64. public function setQty(int $qty): self
  65. {
  66. $this->qty = $qty;
  67. return $this;
  68. }
  69. public function getOrderParent(): ?Order
  70. {
  71. return $this->orderParent;
  72. }
  73. public function setOrderParent(?Order $orderParent): self
  74. {
  75. $this->orderParent = $orderParent;
  76. return $this;
  77. }
  78. public function getAmount() {
  79. return $this->getPrice() * $this->getQty();
  80. }
  81. public function getAmountHT() {
  82. return $this->getAmount() - $this->getTva();
  83. }
  84. public function getQtePreCmd(): ?int
  85. {
  86. return $this->qtePreCmd;
  87. }
  88. public function setQtePreCmd(?int $qtePreCmd): self
  89. {
  90. $this->qtePreCmd = $qtePreCmd;
  91. return $this;
  92. }
  93. /**
  94. * @return Collection<int, OrderProductSurface>
  95. */
  96. public function getSurfaces(): Collection
  97. {
  98. return $this->surfaces;
  99. }
  100. public function addSurface(OrderProductSurface $surface): self
  101. {
  102. if (!$this->surfaces->contains($surface)) {
  103. $this->surfaces[] = $surface;
  104. $surface->setOrderProduct($this);
  105. }
  106. return $this;
  107. }
  108. public function removeSurface(OrderProductSurface $surface): self
  109. {
  110. if ($this->surfaces->removeElement($surface)) {
  111. // set the owning side to null (unless already changed)
  112. if ($surface->getOrderProduct() === $this) {
  113. $surface->setOrderProduct(null);
  114. }
  115. }
  116. return $this;
  117. }
  118. public function jsonSerialize()
  119. {
  120. $vars = get_object_vars($this);
  121. unset($vars["orderParent"]);
  122. unset($vars["product"]);
  123. $vars["surfaces"] = $this->getSurfaces()->toArray();;
  124. return $vars;
  125. }
  126. public function getZonesAvecNbrArbres(){
  127. $result = [];
  128. foreach($this->getSurfaces() as $s){
  129. $key = $s->getSurface()->getId();
  130. $result[$key] = ["id" => $key, "qte" => $s->getQte(), "surface" => $s->getSurface()];
  131. }
  132. return $result;
  133. }
  134. public function getOrderProductSansArbres(): ?ViewOrderProductSansArbres
  135. {
  136. return $this->orderProductSansArbres;
  137. }
  138. public function setOrderProductSansArbres(ViewOrderProductSansArbres $orderProductSansArbres): self
  139. {
  140. // set the owning side of the relation if necessary
  141. if ($orderProductSansArbres->getOrderProduct() !== $this) {
  142. $orderProductSansArbres->setOrderProduct($this);
  143. }
  144. $this->orderProductSansArbres = $orderProductSansArbres;
  145. return $this;
  146. }
  147. public function getTva(): ?string
  148. {
  149. return $this->tva;
  150. }
  151. public function setTva(?string $tva): self
  152. {
  153. $this->tva = $tva;
  154. return $this;
  155. }
  156. }