<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Criteria;
/**
* Repairs
*
* @ORM\Table(name="repairs", indexes={@ORM\Index(name="car_id", columns={"car_id"})})
* @ORM\Entity
*/
class Repairs
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var \DateTime
*
* @ORM\Column(name="start", type="date", nullable=true)
*/
private $start;
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=250, nullable=true, options={"comment"="Elnevezés"})
*/
private $title;
/**
* @var \DateTime|null
*
* @ORM\Column(name="finish", type="date", nullable=true)
*/
private $finish;
/**
* @var int|null
*
* @ORM\Column(name="km", type="integer", nullable=true)
*/
private $km;
/**
* @var int|null
*
* @ORM\Column(name="price_sum", type="integer", nullable=true)
*/
private $priceSum;
/**
* @var int|null
*
* @ORM\Column(name="price_sum_br", type="integer", nullable=true)
*/
private $priceSumBr;
/**
* @var string|null
*
* @ORM\Column(name="note", type="text", length=65535, nullable=true)
*/
private $note;
/**
* @var \DateTime
*
* @ORM\Column(name="created", type="datetime", nullable=false)
*/
private $created;
/**
* @var int|null
*
* @ORM\Column(name="price_bodyguard", type="integer", nullable=true)
*/
private $priceBodyguard;
/**
* @var int|null
*
* @ORM\Column(name="sum_bodyguard", type="integer", nullable=true)
*/
private $sumBodyguard;
/**
* @var int|null
*
* @ORM\Column(name="price_paint", type="integer", nullable=true)
*/
private $pricePaint;
/**
* @var int|null
*
* @ORM\Column(name="sum_paint", type="integer", nullable=true)
*/
private $sumPaint;
/**
* @var int|null
*
* @ORM\Column(name="price_assembly", type="integer", nullable=true)
*/
private $priceAssembly;
/**
* @var int|null
*
* @ORM\Column(name="sum_assembly", type="integer", nullable=true)
*/
private $sumAssembly;
/**
* @var int|null
*
* @ORM\Column(name="sum_other", type="integer", nullable=true)
*/
private $sumOther;
/**
* @var int|null
*
* @ORM\Column(name="sum_material", type="integer", nullable=true)
*/
private $sumMaterial;
/**
* @var int
*
* @ORM\Column(name="tax", type="string", nullable=false)
*/
private $tax;
/**
* @var \Cars
*
* @ORM\ManyToOne(targetEntity="Cars")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="car_id", referencedColumnName="id")
* })
*/
private $car;
/**
* @ORM\OneToMany(targetEntity=RepairItems::class, mappedBy="repair", cascade={"persist"},orphanRemoval=true)
*/
public $repairItems;
/**
* @ORM\OneToMany(targetEntity=Attachment::class, mappedBy="repair", cascade={"persist"},orphanRemoval=true)
*/
public $attachments;
/**
* @var \DateTime
*
* @ORM\Column(name="modified", type="datetime", nullable=true, options={"comment"="Módosítva"})
*/
private $modified;
/**
* @ORM\OneToMany(targetEntity=InventoryItems::class, mappedBy="repairs", cascade={"persist"},orphanRemoval=true)
*/
private $inventoryItem;
public function __construct()
{
$this->created = new \DateTime();
$this->repairItems = new ArrayCollection();
$this->attachments = new ArrayCollection();
$this->inventoryItem = new ArrayCollection();
}
public function setId(int $id): self
{
$this->id = $id;
return $this;
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(?string $title): self
{
$this->title = $title;
return $this;
}
public function getStart(): ?\DateTimeInterface
{
return $this->start;
}
public function setStart(?\DateTimeInterface $start): self
{
$this->start = $start;
return $this;
}
public function getFinish(): ?\DateTimeInterface
{
return $this->finish;
}
public function setFinish(?\DateTimeInterface $finish): self
{
$this->finish = $finish;
return $this;
}
public function getKm(): ?int
{
return $this->km;
}
public function setKm(?int $km): self
{
$this->km = $km;
return $this;
}
public function getTax(): ?string
{
return $this->tax;
}
public function setTax(?string $tax): self
{
$this->tax = $tax;
return $this;
}
public function getPriceSum(): ?int
{
return $this->priceSum;
}
public function setPriceSum(?int $priceSum): self
{
$this->priceSum = $priceSum;
return $this;
}
public function getPriceSumBr(): ?int
{
return $this->priceSumBr;
}
public function setPriceSumBr(?int $priceSumBr): self
{
$this->priceSumBr = $priceSumBr;
return $this;
}
public function getNote(): ?string
{
return $this->note;
}
public function setNote(?string $note): self
{
$this->note = $note;
return $this;
}
public function getCreated(): ?\DateTimeInterface
{
return $this->created;
}
public function setCreated(\DateTimeInterface $created): self
{
$this->created = $created;
return $this;
}
public function getCar(): ?Cars
{
return $this->car;
}
public function setCar(?Cars $car): self
{
$this->car = $car;
return $this;
}
/**
* @return Collection|RepairItems[]
*/
public function getRepairItems(): Collection
{
return $this->repairItems;
}
/* public function addRepairItem(RepairItems $repairItem): self
{
if (!$this->repairItems->contains($repairItem)) {
$repairItem->setRepair($this);
$this->repairItems[] = $repairItem;
}
return $this;
}
public function removeRepairItem(RepairItems $repairItem): self
{
if ($this->repairItems->removeElement($repairItem)) {
// set the owning side to null (unless already changed)
if ($repairItem->getRepair() === $this) {
$repairItem->setRepair(null);
}
}
return $this;
}
*/
/**
* @return Collection|RepairItems[]
*/
public function getRepairPaintItems(): Collection
{
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq('type', RepairItems::PAINT));
return $this->repairItems->matching($criteria);
}
public function addRepairPaintItem(RepairItems $repairItem): self
{
if (!$this->repairItems->contains($repairItem)) {
$repairItem->setType(RepairItems::PAINT);
if (($repairItem->getPriceQty() === null || $repairItem->getPriceQty() == 0) && $this->getPricePaint() !== null) {
$repairItem->setPriceQty($this->pricePaint);
}
$repairItem->setPriceSum($repairItem->getPriceQty() * $repairItem->getQty());
//XXX NEED TO FIX THE OTHER TYPE'S
$repairItem->setRepair($this);
$this->repairItems[] = $repairItem;
}
return $this;
}
public function removeRepairPaintItem(RepairItems $repairItem): self
{
if ($this->repairItems->removeElement($repairItem)) {
// set the owning side to null (unless already changed)
/*if ($repairItem->getRepair() === $this) {
$repairItem->setRepair(null);
}*/
}
return $this;
}
/**
* @return Collection|RepairItems[]
*/
public function getRepairAssemblyItems(): Collection
{
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq('type', RepairItems::ASSEMBLY));
return $this->repairItems->matching($criteria);
}
public function addRepairAssemblyItem(RepairItems $repairItem): self
{
if (!$this->repairItems->contains($repairItem)) {
$repairItem->setType(RepairItems::ASSEMBLY);
if ($this->getPriceAssembly() !== null) {
$repairItem->setPriceQty($this->priceAssembly);
}
$repairItem->setRepair($this);
$this->repairItems[] = $repairItem;
}
return $this;
}
public function removeRepairAssemblyItem(RepairItems $repairItem): self
{
if ($this->repairItems->removeElement($repairItem)) {
// set the owning side to null (unless already changed)
if ($repairItem->getRepair() === $this) {
$repairItem->setRepair(null);
}
}
return $this;
}
/**
* @return Collection|RepairItems[]
*/
public function getRepairBodyguardItems(): Collection
{
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq('type', RepairItems::BODYGUARD));
return $this->repairItems->matching($criteria);
}
public function addRepairBodyguardItem(RepairItems $repairItem): self
{
if (!$this->repairItems->contains($repairItem)) {
$repairItem->setType(RepairItems::BODYGUARD);
if ($this->getPriceBodyguard() !== null) {
$repairItem->setPriceQty($this->priceBodyguard);
}
$repairItem->setRepair($this);
$this->repairItems[] = $repairItem;
}
return $this;
}
public function removeRepairBodyguardItem(RepairItems $repairItem): self
{
if ($this->repairItems->removeElement($repairItem)) {
// set the owning side to null (unless already changed)
if ($repairItem->getRepair() === $this) {
$repairItem->setRepair(null);
}
}
return $this;
}
/**
* @return Collection|RepairItems[]
*/
public function getRepairOtherItems(): Collection
{
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq('type', RepairItems::OTHER));
return $this->repairItems->matching($criteria);
}
public function addRepairOtherItem(RepairItems $repairItem): self
{
if (!$this->repairItems->contains($repairItem)) {
$repairItem->setType(RepairItems::OTHER);
$repairItem->setRepair($this);
$this->repairItems[] = $repairItem;
}
return $this;
}
public function removeRepairOtherItem(RepairItems $repairItem): self
{
if ($this->repairItems->removeElement($repairItem)) {
// set the owning side to null (unless already changed)
if ($repairItem->getRepair() === $this) {
$repairItem->setRepair(null);
}
}
return $this;
}
/**
* @return Collection|RepairItems[]
*/
public function getRepairMaterialItems(): Collection
{
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq('type', RepairItems::MATERIAL));
return $this->repairItems->matching($criteria);
}
public function addRepairMaterialItem(RepairItems $repairItem): self
{
if (!$this->repairItems->contains($repairItem)) {
$repairItem->setType(RepairItems::MATERIAL);
$repairItem->setRepair($this);
$this->repairItems[] = $repairItem;
}
return $this;
}
public function removeRepairMaterialItem(RepairItems $repairItem): self
{
if ($this->repairItems->removeElement($repairItem)) {
// set the owning side to null (unless already changed)
if ($repairItem->getRepair() === $this) {
$repairItem->setRepair(null);
}
}
return $this;
}
/**
* @return Collection|Attachment[]
*/
public function getAttachments(): Collection
{
return $this->attachments;
}
public function addAttachment(Attachment $photo): self
{
if (!$this->attachments->contains($photo)) {
$photo->setRepair($this);
$this->attachments[] = $photo;
}
return $this;
}
public function removeAttachment(Attachment $photo): self
{
if ($this->attachments->removeElement($photo)) {
// set the owning side to null (unless already changed)
if ($photo->getRepair() === $this) {
$photo->setRepair(null);
}
}
return $this;
}
public function getPriceBodyguard(): ?int
{
return $this->priceBodyguard;
}
public function setPriceBodyguard(?int $priceBodyguard): self
{
$this->priceBodyguard = $priceBodyguard;
return $this;
}
public function getPricePaint(): ?int
{
return $this->pricePaint;
}
public function setPricePaint(?int $pricePaint): self
{
$this->pricePaint = $pricePaint;
return $this;
}
public function getPriceAssembly(): ?int
{
return $this->priceAssembly;
}
public function setPriceAssembly(?int $priceAssembly): self
{
$this->priceAssembly = $priceAssembly;
return $this;
}
public function __toString()
{
$title = $this->title ? ' - ' . $this->title : ' ';
$start = $this->getStart() ? " - " . $this->getStart()->format('Ymd') : ' ';
$plate = $this->getCar() ? $this->getCar()->getPlateNumber() : 'No vehicle associated';
$km = $this->getKm() ? ' - ' . $this->getKm() . 'km' : ' ';
return $plate . $title . $km . $start;
}
public function rowCss($days = 30)
{
$now = new \DateTime();
if ($this->start) {
$nd = \DateTime::createFromFormat("Y-m-d", date('Y-m-d', strtotime($this->start->format('Y-m-d') . "+$days days")));
if ($this->finish == null && $nd < $now) {
return "alert alert-warning";
} else if ($this->finish == null) {
return "alert alert-success";
}
}
return "";
}
public function getSumPaint(): ?int
{
return $this->sumPaint;
}
public function setSumPaint(?int $sumPaint): self
{
$this->sumPaint = $sumPaint;
return $this;
}
public function getSumBodyguard(): ?int
{
return $this->sumBodyguard;
}
public function setSumBodyguard(?int $sumBodyguard): self
{
$this->sumBodyguard = $sumBodyguard;
return $this;
}
public function getSumAssembly(): ?int
{
return $this->sumAssembly;
}
public function setSumAssembly(?int $sumAssembly): self
{
$this->sumAssembly = $sumAssembly;
return $this;
}
public function getSumOther(): ?int
{
return $this->sumOther;
}
public function setSumOther(?int $sumOther): self
{
$this->sumOther = $sumOther;
return $this;
}
public function getSumMaterial(): ?int
{
return $this->sumMaterial;
}
public function setSumMaterial(?int $sumMaterial): self
{
$this->sumMaterial = $sumMaterial;
return $this;
}
public function numOfAttachments()
{
return $this->attachments ? count($this->attachments) : 0;
}
public function getModified(): ?\DateTimeInterface
{
return $this->modified;
}
public function setModified(\DateTimeInterface $modified): self
{
$this->modified = $modified;
return $this;
}
public function getTaxPrice()
{
if ($this->getPriceSumBr() > $this->getPriceSum()) {
return $this->getPriceSumBr() - $this->getPriceSum();
}
return 0;
}
/**
* @return Collection<int, InventoryItems>
*/
public function getInventoryItem(): Collection
{
return $this->inventoryItem;
}
public function addInventoryItem(InventoryItems $inventoryItem): self
{
if (!$this->inventoryItem->contains($inventoryItem)) {
$this->inventoryItem[] = $inventoryItem;
$inventoryItem->setRepairs($this);
}
return $this;
}
public function removeInventoryItem(InventoryItems $inventoryItem): self
{
if ($this->inventoryItem->removeElement($inventoryItem)) {
// set the owning side to null (unless already changed)
if ($inventoryItem->getRepairs() === $this) {
$inventoryItem->setRepairs(null);
}
}
return $this;
}
}