src/Entity/ProjectProducts.php line 13

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