src/Entity/ProjectProducts.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ProjectProductsRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClass: ProjectProductsRepository::class)]
  8. class ProjectProducts
  9. {
  10. #[ORM\Id]
  11. #[ORM\GeneratedValue]
  12. #[ORM\Column(type: 'integer')]
  13. private $id;
  14. #[ORM\Column(type: 'string', length: 255)]
  15. private $name;
  16. #[ORM\Column(type: 'text', nullable: true)]
  17. private $note;
  18. #[ORM\Column(type: 'float', nullable: true)]
  19. private $est_hour;
  20. #[ORM\Column(type: 'integer', nullable: true)]
  21. private $net_price;
  22. #[ORM\Column(type: 'datetime', nullable: true)]
  23. private $created;
  24. #[ORM\ManyToOne(targetEntity: Projects::class, inversedBy: 'projectProducts')]
  25. private $project;
  26. #[ORM\Column(type: 'integer', nullable: true)]
  27. private $qty;
  28. #[ORM\Column(type: 'integer', nullable: true)]
  29. private $qty_finish;
  30. #[ORM\OneToMany(targetEntity: Material::class, mappedBy: 'projectProducts', cascade: ['persist'], orphanRemoval: true)]
  31. private $materials;
  32. #[ORM\OneToMany(targetEntity: WorkHours::class, mappedBy: 'projectProduct')]
  33. private $workHours;
  34. #[ORM\Column(type: 'datetime', nullable: true)]
  35. private $closed;
  36. #[ORM\Column(type: 'boolean')]
  37. private $isClosed;
  38. #[ORM\OneToMany(targetEntity: Events::class, mappedBy: 'product')]
  39. private $events;
  40. #[ORM\OneToMany(mappedBy: 'projectProduct', targetEntity: ProductWarranty::class)]
  41. private Collection $productWarranties;
  42. public function __construct()
  43. {
  44. $this->created = new \DateTime();
  45. $this->materials = new ArrayCollection();
  46. $this->workHours = new ArrayCollection();
  47. $this->events = new ArrayCollection();
  48. $this->productWarranties = new ArrayCollection();
  49. }
  50. public function getId(): ?int
  51. {
  52. return $this->id;
  53. }
  54. public function getName(): ?string
  55. {
  56. return $this->name;
  57. }
  58. public function setName(string $name): self
  59. {
  60. $this->name = $name;
  61. return $this;
  62. }
  63. public function getNote(): ?string
  64. {
  65. return $this->note;
  66. }
  67. public function setNote(?string $note): self
  68. {
  69. $this->note = $note;
  70. return $this;
  71. }
  72. public function getEstHour(): ?float
  73. {
  74. return $this->est_hour;
  75. }
  76. public function setEstHour(?float $est_hour): self
  77. {
  78. $this->est_hour = $est_hour;
  79. return $this;
  80. }
  81. public function getNetPrice(): ?int
  82. {
  83. return $this->net_price;
  84. }
  85. public function setNetPrice(?int $net_price): self
  86. {
  87. $this->net_price = $net_price;
  88. return $this;
  89. }
  90. public function getCreated(): ?\DateTimeInterface
  91. {
  92. return $this->created;
  93. }
  94. public function setCreated(?\DateTimeInterface $created): self
  95. {
  96. $this->created = $created;
  97. return $this;
  98. }
  99. public function getProject(): ?Projects
  100. {
  101. return $this->project;
  102. }
  103. public function setProject(?Projects $project): self
  104. {
  105. $this->project = $project;
  106. return $this;
  107. }
  108. public function getQty(): ?int
  109. {
  110. return $this->qty;
  111. }
  112. public function setQty(?int $qty): self
  113. {
  114. $this->qty = $qty;
  115. return $this;
  116. }
  117. public function getQtyFinish(): ?int
  118. {
  119. return $this->qty_finish;
  120. }
  121. public function setQtyFinish(?int $qty_finish): self
  122. {
  123. $this->qty_finish = $qty_finish;
  124. return $this;
  125. }
  126. /**
  127. * @return Collection|Material[]
  128. */
  129. public function getMaterials(): Collection
  130. {
  131. return $this->materials;
  132. }
  133. public function addMaterial(Material $material): self
  134. {
  135. if (!$this->materials->contains($material)) {
  136. $this->materials[] = $material;
  137. $material->setProjectProducts($this);
  138. }
  139. return $this;
  140. }
  141. public function removeMaterial(Material $material): self
  142. {
  143. if ($this->materials->removeElement($material)) {
  144. // set the owning side to null (unless already changed)
  145. if ($material->getProjectProducts() === $this) {
  146. $material->setProjectProducts(null);
  147. }
  148. }
  149. return $this;
  150. }
  151. /**
  152. * @return Collection|WorkHours[]
  153. */
  154. public function getWorkHoursSum()
  155. {
  156. $sum = 0;
  157. foreach ($this->workHours as $key => $value) {
  158. $sum += $value->getHours();
  159. }
  160. return $sum;
  161. }
  162. /**
  163. * @return Collection|WorkHours[]
  164. */
  165. public function getWorkHours(): Collection
  166. {
  167. return $this->workHours;
  168. }
  169. public function addWorkHour(WorkHours $workHour): self
  170. {
  171. if (!$this->workHours->contains($workHour)) {
  172. $this->workHours[] = $workHour;
  173. $workHour->setProjectProduct($this);
  174. }
  175. return $this;
  176. }
  177. public function removeWorkHour(WorkHours $workHour): self
  178. {
  179. if ($this->workHours->removeElement($workHour)) {
  180. // set the owning side to null (unless already changed)
  181. if ($workHour->getProjectProduct() === $this) {
  182. $workHour->setProjectProduct(null);
  183. }
  184. }
  185. return $this;
  186. }
  187. public function __toString()
  188. {
  189. $customer = $this->project != null ? $this->project->getCustomer()->getName() : "";
  190. $project = $this->project != null ? $this->project->getName() : "";
  191. return $customer . ' » ' . $project . " » " . $this->name;
  192. }
  193. public function getClosed(): ?\DateTimeInterface
  194. {
  195. return $this->closed;
  196. }
  197. public function setClosed(?\DateTimeInterface $closed): self
  198. {
  199. $this->closed = $closed;
  200. return $this;
  201. }
  202. public function getIsClosed(): ?bool
  203. {
  204. return $this->isClosed;
  205. }
  206. public function setIsClosed(bool $isClosed): self
  207. {
  208. $this->isClosed = $isClosed;
  209. $this->closed = $isClosed ? new \DateTime() : null;
  210. return $this;
  211. }
  212. /**
  213. * @return Collection|Events[]
  214. */
  215. public function getEvents(): Collection
  216. {
  217. return $this->events;
  218. }
  219. public function addEvent(Events $event): self
  220. {
  221. if (!$this->events->contains($event)) {
  222. $this->events[] = $event;
  223. $event->setProduct($this);
  224. }
  225. return $this;
  226. }
  227. public function removeEvent(Events $event): self
  228. {
  229. if ($this->events->removeElement($event)) {
  230. // set the owning side to null (unless already changed)
  231. if ($event->getProduct() === $this) {
  232. $event->setProduct(null);
  233. }
  234. }
  235. return $this;
  236. }
  237. /**
  238. * @return Collection<int, ProductWarranty>
  239. */
  240. public function getProductWarranties(): Collection
  241. {
  242. return $this->productWarranties;
  243. }
  244. public function addProductWarranty(ProductWarranty $productWarranty): static
  245. {
  246. if (!$this->productWarranties->contains($productWarranty)) {
  247. $this->productWarranties->add($productWarranty);
  248. $productWarranty->setProjectProduct($this);
  249. }
  250. return $this;
  251. }
  252. public function removeProductWarranty(ProductWarranty $productWarranty): static
  253. {
  254. if ($this->productWarranties->removeElement($productWarranty)) {
  255. // set the owning side to null (unless already changed)
  256. if ($productWarranty->getProjectProduct() === $this) {
  257. $productWarranty->setProjectProduct(null);
  258. }
  259. }
  260. return $this;
  261. }
  262. }