<?php
namespace App\Entity;
use App\Repository\MachineRepository;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
/**
* @ORM\Entity(repositoryClass=MachineRepository::class)
*/
class Machine
{
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="string", length=255)
*/
private $code;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $invoiceDescription;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $technicalNotes;
/**
* @ORM\ManyToOne(targetEntity=Machine::class, inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id" )
*/
private $parent;
/**
* @ORM\OneToMany(targetEntity=Machine::class, mappedBy="parent")
*/
private $children;
/**
* @ORM\ManyToMany(targetEntity=PaperSize::class, mappedBy="machines", cascade={"persist"})
*/
private $paperSizes;
/**
* @ORM\OneToMany(targetEntity=MachinePaperSizeMatrix::class, mappedBy="machine", cascade={"persist", "remove"})
*/
private $machinePaperSizeMatrices;
/**
* @ORM\ManyToMany(targetEntity=Task::class, inversedBy="machines", cascade={"persist"})
*/
private $tasks;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $waste;
/**
* @ORM\Column(type="decimal", precision=10, scale=3, nullable=true)
*/
private $spoilage;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $setupTime;
/**
* @ORM\Column(type="decimal", precision=10, scale=4, nullable=true)
*/
private $rate;
/**
* @ORM\OneToMany(targetEntity=MachineCostMatrix::class, mappedBy="machine", orphanRemoval=true, cascade={"persist", "remove"})
*/
private $machineCostMatrices;
/**
* @ORM\OneToMany(targetEntity=MachineTimeMatrix::class, mappedBy="machine", orphanRemoval=true, cascade={"persist", "remove"})
*/
private $machineTimeMatrices;
public function __construct()
{
$this->children = new ArrayCollection();
$this->paperSizes = new ArrayCollection();
$this->machinePaperSizeMatrices = new ArrayCollection();
$this->tasks = new ArrayCollection();
$this->machineCostMatrices = new ArrayCollection();
$this->machineTimeMatrices = 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 getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
public function getInvoiceDescription(): ?string
{
return $this->invoiceDescription;
}
public function setInvoiceDescription(?string $invoiceDescription): self
{
$this->invoiceDescription = $invoiceDescription;
return $this;
}
public function getTechnicalNotes(): ?string
{
return $this->technicalNotes;
}
public function setTechnicalNotes(?string $technicalNotes): self
{
$this->technicalNotes = $technicalNotes;
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getChildren(): Collection
{
return $this->children;
}
public function addChild(self $child): self
{
if (!$this->children->contains($child)) {
$this->children[] = $child;
$child->setParent($this);
}
return $this;
}
public function removeChild(self $child): self
{
if ($this->children->removeElement($child)) {
// set the owning side to null (unless already changed)
if ($child->getParent() === $this) {
$child->setParent(null);
}
}
return $this;
}
/**
* @return Collection<int, PaperSize>
*/
public function getPaperSizes(): Collection
{
return $this->paperSizes;
}
public function addPaperSize(PaperSize $paperSize): self
{
if (!$this->paperSizes->contains($paperSize)) {
$this->paperSizes[] = $paperSize;
$paperSize->addMachine($this);
}
return $this;
}
public function removePaperSize(PaperSize $paperSize): self
{
if ($this->paperSizes->removeElement($paperSize)) {
$paperSize->removeMachine($this);
}
return $this;
}
/**
* @return Collection<int, MachinePaperSizeMatrix>
*/
public function getMachinePaperSizeMatrices(): Collection
{
return $this->machinePaperSizeMatrices;
}
public function addMachinePaperSizeMatrix(MachinePaperSizeMatrix $machinePaperSizeMatrix): self
{
if (!$this->machinePaperSizeMatrices->contains($machinePaperSizeMatrix)) {
$this->machinePaperSizeMatrices[] = $machinePaperSizeMatrix;
$machinePaperSizeMatrix->setMachine($this);
}
return $this;
}
public function removeMachinePaperSizeMatrix(MachinePaperSizeMatrix $machinePaperSizeMatrix): self
{
if ($this->machinePaperSizeMatrices->removeElement($machinePaperSizeMatrix)) {
// set the owning side to null (unless already changed)
if ($machinePaperSizeMatrix->getMachine() === $this) {
$machinePaperSizeMatrix->setMachine(null);
}
}
return $this;
}
/**
* @return Collection<int, Task>
*/
public function getTasks(): Collection
{
return $this->tasks;
}
public function addTask(Task $task): self
{
if (!$this->tasks->contains($task)) {
$this->tasks[] = $task;
}
return $this;
}
public function removeTask(Task $task): self
{
$this->tasks->removeElement($task);
return $this;
}
public function getWaste(): ?int
{
return $this->waste;
}
public function setWaste(?int $waste): self
{
$this->waste = $waste;
return $this;
}
public function getSpoilage(): ?string
{
return $this->spoilage;
}
public function setSpoilage(?string $spoilage): self
{
$this->spoilage = $spoilage;
return $this;
}
public function getSetupTime(): ?int
{
return $this->setupTime;
}
public function setSetupTime(?int $setupTime): self
{
$this->setupTime = $setupTime;
return $this;
}
public function getRate(): ?string
{
return $this->rate;
}
public function setRate(?string $rate): self
{
$this->rate = $rate;
return $this;
}
/**
* @return Collection<int, MachineCostMatrix>
*/
public function getMachineCostMatrices(): Collection
{
return $this->machineCostMatrices;
}
public function addMachineCostMatrix(MachineCostMatrix $machineCostMatrix): self
{
if (!$this->machineCostMatrices->contains($machineCostMatrix)) {
$this->machineCostMatrices[] = $machineCostMatrix;
$machineCostMatrix->setMachine($this);
}
return $this;
}
public function removeMachineCostMatrix(MachineCostMatrix $machineCostMatrix): self
{
if ($this->machineCostMatrices->removeElement($machineCostMatrix)) {
// set the owning side to null (unless already changed)
if ($machineCostMatrix->getMachine() === $this) {
$machineCostMatrix->setMachine(null);
}
}
return $this;
}
/**
* @return Collection<int, MachineTimeMatrix>
*/
public function getMachineTimeMatrices(): Collection
{
return $this->machineTimeMatrices;
}
public function addMachineTimeMatrix(MachineTimeMatrix $machineTimeMatrix): self
{
if (!$this->machineTimeMatrices->contains($machineTimeMatrix)) {
$this->machineTimeMatrices[] = $machineTimeMatrix;
$machineTimeMatrix->setMachine($this);
}
return $this;
}
public function removeMachineTimeMatrix(MachineTimeMatrix $machineTimeMatrix): self
{
if ($this->machineTimeMatrices->removeElement($machineTimeMatrix)) {
// set the owning side to null (unless already changed)
if ($machineTimeMatrix->getMachine() === $this) {
$machineTimeMatrix->setMachine(null);
}
}
return $this;
}
public function __clone() {
$paperSizes = new ArrayCollection();
foreach ($this->paperSizes as $paperSize) {
/** @var Papersize $paperSize */
$paperSize->addMachine($this);
$paperSizes->add($paperSize);
}
$now = new DateTime('now');
$machinePaperSizeMatrices = new ArrayCollection();
foreach ($this->machinePaperSizeMatrices as $machinePaperSizeMatrix) {
$newMachinePaperSizeMatrix = clone $machinePaperSizeMatrix;
$newMachinePaperSizeMatrix->setCreatedAt($now);
$newMachinePaperSizeMatrix->setUpdatedAt($now);
$newMachinePaperSizeMatrix->setMachine($this);
$machinePaperSizeMatrices->add($newMachinePaperSizeMatrix);
}
$this->machinePaperSizeMatrices = $machinePaperSizeMatrices;
/* machineCostMatrices */
$machineCostMatrices = new ArrayCollection();
foreach ($this->machineCostMatrices as $machineCostMatrix) {
$newMachineCostMatrix = clone $machineCostMatrix;
$newMachineCostMatrix->setCreatedAt($now);
$newMachineCostMatrix->setUpdatedAt($now);
$newMachineCostMatrix->setMachine($this);
$machineCostMatrices->add($newMachineCostMatrix);
}
$this->machineCostMatrices = $machineCostMatrices;
/* machineTimeMatrices */
$machineTimeMatrices = new ArrayCollection();
foreach ($this->machineTimeMatrices as $machineTimeMatrix) {
$newMachineTimeMatrix = clone $machineTimeMatrix;
$newMachineTimeMatrix->setMachine($this);
$machineTimeMatrices->add($newMachineTimeMatrix);
}
$this->machineTimeMatrices = $machineTimeMatrices;
/* Tasks */
$tasks = new ArrayCollection();
foreach ($this->tasks as $task) {
$task->addMachine($this);
$tasks->add($task);
}
$this->tasks = $tasks;
}
public function getCalculatorDisplayName():string
{
return '['.$this->code.']['.$this->name.']';
}
public function __toString() {
return $this->name;
}
}