<?php
namespace App\Entity;
use App\Repository\ProjectProductsRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ProjectProductsRepository::class)
*/
class ProjectProducts
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $note;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $est_hour;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $net_price;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $created;
/**
* @ORM\ManyToOne(targetEntity=Projects::class, inversedBy="projectProducts")
*/
private $project;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $qty;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $qty_finish;
/**
* @ORM\OneToMany(targetEntity=Material::class, mappedBy="projectProducts", cascade={"persist"}, orphanRemoval=true)
*/
private $materials;
/**
* @ORM\OneToMany(targetEntity=WorkHours::class, mappedBy="projectProduct")
*/
private $workHours;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $closed;
/**
* @ORM\Column(type="boolean")
*/
private $isClosed;
/**
* @ORM\OneToMany(targetEntity=Events::class, mappedBy="product")
*/
private $events;
public function __construct()
{
$this->created = new \DateTime();
$this->materials = new ArrayCollection();
$this->workHours = new ArrayCollection();
$this->events = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getNote(): ?string
{
return $this->note;
}
public function setNote(?string $note): self
{
$this->note = $note;
return $this;
}
public function getEstHour(): ?float
{
return $this->est_hour;
}
public function setEstHour(?float $est_hour): self
{
$this->est_hour = $est_hour;
return $this;
}
public function getNetPrice(): ?int
{
return $this->net_price;
}
public function setNetPrice(?int $net_price): self
{
$this->net_price = $net_price;
return $this;
}
public function getCreated(): ?\DateTimeInterface
{
return $this->created;
}
public function setCreated(?\DateTimeInterface $created): self
{
$this->created = $created;
return $this;
}
public function getProject(): ?Projects
{
return $this->project;
}
public function setProject(?Projects $project): self
{
$this->project = $project;
return $this;
}
public function getQty(): ?int
{
return $this->qty;
}
public function setQty(?int $qty): self
{
$this->qty = $qty;
return $this;
}
public function getQtyFinish(): ?int
{
return $this->qty_finish;
}
public function setQtyFinish(?int $qty_finish): self
{
$this->qty_finish = $qty_finish;
return $this;
}
/**
* @return Collection|Material[]
*/
public function getMaterials(): Collection
{
return $this->materials;
}
public function addMaterial(Material $material): self
{
if (!$this->materials->contains($material)) {
$this->materials[] = $material;
$material->setProjectProducts($this);
}
return $this;
}
public function removeMaterial(Material $material): self
{
if ($this->materials->removeElement($material)) {
// set the owning side to null (unless already changed)
if ($material->getProjectProducts() === $this) {
$material->setProjectProducts(null);
}
}
return $this;
}
/**
* @return Collection|WorkHours[]
*/
public function getWorkHoursSum()
{
$sum = 0;
foreach ($this->workHours as $key => $value) {
$sum += $value->getHours();
}
return $sum;
}
/**
* @return Collection|WorkHours[]
*/
public function getWorkHours(): Collection
{
return $this->workHours;
}
public function addWorkHour(WorkHours $workHour): self
{
if (!$this->workHours->contains($workHour)) {
$this->workHours[] = $workHour;
$workHour->setProjectProduct($this);
}
return $this;
}
public function removeWorkHour(WorkHours $workHour): self
{
if ($this->workHours->removeElement($workHour)) {
// set the owning side to null (unless already changed)
if ($workHour->getProjectProduct() === $this) {
$workHour->setProjectProduct(null);
}
}
return $this;
}
public function __toString()
{
$customer = $this->project != null ? $this->project->getCustomer()->getName() : "";
$project = $this->project != null ? $this->project->getName() : "";
return $customer . ' » ' . $project . " » " . $this->name;
}
public function getClosed(): ?\DateTimeInterface
{
return $this->closed;
}
public function setClosed(?\DateTimeInterface $closed): self
{
$this->closed = $closed;
return $this;
}
public function getIsClosed(): ?bool
{
return $this->isClosed;
}
public function setIsClosed(bool $isClosed): self
{
$this->isClosed = $isClosed;
$this->closed = $isClosed ? new \DateTime() : null;
return $this;
}
/**
* @return Collection|Events[]
*/
public function getEvents(): Collection
{
return $this->events;
}
public function addEvent(Events $event): self
{
if (!$this->events->contains($event)) {
$this->events[] = $event;
$event->setProduct($this);
}
return $this;
}
public function removeEvent(Events $event): self
{
if ($this->events->removeElement($event)) {
// set the owning side to null (unless already changed)
if ($event->getProduct() === $this) {
$event->setProduct(null);
}
}
return $this;
}
}