src/Entity/Repairs.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Doctrine\Common\Collections\Criteria;
  7. /**
  8.  * Repairs
  9.  *
  10.  * @ORM\Table(name="repairs", indexes={@ORM\Index(name="car_id", columns={"car_id"})})
  11.  * @ORM\Entity
  12.  */
  13. class Repairs
  14. {
  15.     /**
  16.      * @var int
  17.      *
  18.      * @ORM\Column(name="id", type="integer", nullable=false)
  19.      * @ORM\Id
  20.      * @ORM\GeneratedValue(strategy="IDENTITY")
  21.      */
  22.     private $id;
  23.     /**
  24.      * @var \DateTime
  25.      *
  26.      * @ORM\Column(name="start", type="date", nullable=true)
  27.      */
  28.     private $start;
  29.     /**
  30.      * @var string
  31.      *
  32.      * @ORM\Column(name="title", type="string", length=250, nullable=true, options={"comment"="Elnevezés"})
  33.      */
  34.     private $title;
  35.     /**
  36.      * @var \DateTime|null
  37.      *
  38.      * @ORM\Column(name="finish", type="date", nullable=true)
  39.      */
  40.     private $finish;
  41.     /**
  42.      * @var int|null
  43.      *
  44.      * @ORM\Column(name="km", type="integer", nullable=true)
  45.      */
  46.     private $km;
  47.     /**
  48.      * @var int|null
  49.      *
  50.      * @ORM\Column(name="price_sum", type="integer", nullable=true)
  51.      */
  52.     private $priceSum;
  53.     /**
  54.      * @var int|null
  55.      *
  56.      * @ORM\Column(name="price_sum_br", type="integer", nullable=true)
  57.      */
  58.     private $priceSumBr;
  59.     /**
  60.      * @var string|null
  61.      *
  62.      * @ORM\Column(name="note", type="text", length=65535, nullable=true)
  63.      */
  64.     private $note;
  65.     /**
  66.      * @var \DateTime
  67.      *
  68.      * @ORM\Column(name="created", type="datetime", nullable=false)
  69.      */
  70.     private $created;
  71.     /**
  72.      * @var int|null
  73.      *
  74.      * @ORM\Column(name="price_bodyguard", type="integer", nullable=true)
  75.      */
  76.     private $priceBodyguard;
  77.     /**
  78.      * @var int|null
  79.      *
  80.      * @ORM\Column(name="sum_bodyguard", type="integer", nullable=true)
  81.      */
  82.     private $sumBodyguard;
  83.     /**
  84.      * @var int|null
  85.      *
  86.      * @ORM\Column(name="price_paint", type="integer", nullable=true)
  87.      */
  88.     private $pricePaint;
  89.     /**
  90.      * @var int|null
  91.      *
  92.      * @ORM\Column(name="sum_paint", type="integer", nullable=true)
  93.      */
  94.     private $sumPaint;
  95.     /**
  96.      * @var int|null
  97.      *
  98.      * @ORM\Column(name="price_assembly", type="integer", nullable=true)
  99.      */
  100.     private $priceAssembly;
  101.     /**
  102.      * @var int|null
  103.      *
  104.      * @ORM\Column(name="sum_assembly", type="integer", nullable=true)
  105.      */
  106.     private $sumAssembly;
  107.     /**
  108.      * @var int|null
  109.      *
  110.      * @ORM\Column(name="sum_other", type="integer", nullable=true)
  111.      */
  112.     private $sumOther;
  113.     /**
  114.      * @var int|null
  115.      *
  116.      * @ORM\Column(name="sum_material", type="integer", nullable=true)
  117.      */
  118.     private $sumMaterial;
  119.     /**
  120.      * @var int
  121.      *
  122.      * @ORM\Column(name="tax", type="string", nullable=false)
  123.      */
  124.     private $tax;
  125.     /**
  126.      * @var \Cars
  127.      *
  128.      * @ORM\ManyToOne(targetEntity="Cars")
  129.      * @ORM\JoinColumns({
  130.      *   @ORM\JoinColumn(name="car_id", referencedColumnName="id")
  131.      * })
  132.      */
  133.     private $car;
  134.     /**
  135.      * @ORM\OneToMany(targetEntity=RepairItems::class, mappedBy="repair", cascade={"persist"},orphanRemoval=true)
  136.      */
  137.     public $repairItems;
  138.     /**
  139.      * @ORM\OneToMany(targetEntity=Attachment::class, mappedBy="repair", cascade={"persist"},orphanRemoval=true)
  140.      */
  141.     public $attachments;
  142.     /**
  143.      * @var \DateTime
  144.      *
  145.      * @ORM\Column(name="modified", type="datetime", nullable=true, options={"comment"="Módosítva"})
  146.      */
  147.     private $modified;
  148.     /**
  149.      * @ORM\OneToMany(targetEntity=InventoryItems::class, mappedBy="repairs", cascade={"persist"},orphanRemoval=true)
  150.      */
  151.     private $inventoryItem;
  152.     public function __construct()
  153.     {
  154.         $this->created = new \DateTime();
  155.         $this->repairItems = new ArrayCollection();
  156.         $this->attachments = new ArrayCollection();
  157.         $this->inventoryItem = new ArrayCollection();
  158.     }
  159.     public function setId(int $id): self
  160.     {
  161.         $this->id = $id;
  162.         return $this;
  163.     }
  164.     public function getId(): ?int
  165.     {
  166.         return $this->id;
  167.     }
  168.     public function getTitle(): ?string
  169.     {
  170.         return $this->title;
  171.     }
  172.     public function setTitle(?string $title): self
  173.     {
  174.         $this->title = $title;
  175.         return $this;
  176.     }
  177.     public function getStart(): ?\DateTimeInterface
  178.     {
  179.         return $this->start;
  180.     }
  181.     public function setStart(?\DateTimeInterface $start): self
  182.     {
  183.         $this->start = $start;
  184.         return $this;
  185.     }
  186.     public function getFinish(): ?\DateTimeInterface
  187.     {
  188.         return $this->finish;
  189.     }
  190.     public function setFinish(?\DateTimeInterface $finish): self
  191.     {
  192.         $this->finish = $finish;
  193.         return $this;
  194.     }
  195.     public function getKm(): ?int
  196.     {
  197.         return $this->km;
  198.     }
  199.     public function setKm(?int $km): self
  200.     {
  201.         $this->km = $km;
  202.         return $this;
  203.     }
  204.     public function getTax(): ?string
  205.     {
  206.         return $this->tax;
  207.     }
  208.     public function setTax(?string $tax): self
  209.     {
  210.         $this->tax = $tax;
  211.         return $this;
  212.     }
  213.     public function getPriceSum(): ?int
  214.     {
  215.         return $this->priceSum;
  216.     }
  217.     public function setPriceSum(?int $priceSum): self
  218.     {
  219.         $this->priceSum = $priceSum;
  220.         return $this;
  221.     }
  222.     public function getPriceSumBr(): ?int
  223.     {
  224.         return $this->priceSumBr;
  225.     }
  226.     public function setPriceSumBr(?int $priceSumBr): self
  227.     {
  228.         $this->priceSumBr = $priceSumBr;
  229.         return $this;
  230.     }
  231.     public function getNote(): ?string
  232.     {
  233.         return $this->note;
  234.     }
  235.     public function setNote(?string $note): self
  236.     {
  237.         $this->note = $note;
  238.         return $this;
  239.     }
  240.     public function getCreated(): ?\DateTimeInterface
  241.     {
  242.         return $this->created;
  243.     }
  244.     public function setCreated(\DateTimeInterface $created): self
  245.     {
  246.         $this->created = $created;
  247.         return $this;
  248.     }
  249.     public function getCar(): ?Cars
  250.     {
  251.         return $this->car;
  252.     }
  253.     public function setCar(?Cars $car): self
  254.     {
  255.         $this->car = $car;
  256.         return $this;
  257.     }
  258.     /**
  259.      * @return Collection|RepairItems[]
  260.      */
  261.     public function getRepairItems(): Collection
  262.     {
  263.         return $this->repairItems;
  264.     }
  265.     /*    public function addRepairItem(RepairItems $repairItem): self
  266.     {
  267.         if (!$this->repairItems->contains($repairItem)) {
  268.             $repairItem->setRepair($this);
  269.             $this->repairItems[] = $repairItem;
  270.         }
  271.         return $this;
  272.     }
  273.     public function removeRepairItem(RepairItems $repairItem): self
  274.     {
  275.         if ($this->repairItems->removeElement($repairItem)) {
  276.             // set the owning side to null (unless already changed)
  277.             if ($repairItem->getRepair() === $this) {
  278.                 $repairItem->setRepair(null);
  279.             }
  280.         }
  281.         return $this;
  282.     }
  283. */
  284.     /**
  285.      * @return Collection|RepairItems[]
  286.      */
  287.     public function getRepairPaintItems(): Collection
  288.     {
  289.         $criteria = Criteria::create();
  290.         $criteria->where(Criteria::expr()->eq('type', RepairItems::PAINT));
  291.         return $this->repairItems->matching($criteria);
  292.     }
  293.     public function addRepairPaintItem(RepairItems $repairItem): self
  294.     {
  295.         if (!$this->repairItems->contains($repairItem)) {
  296.             $repairItem->setType(RepairItems::PAINT);
  297.             if (($repairItem->getPriceQty() === null || $repairItem->getPriceQty() == 0) && $this->getPricePaint() !== null) {
  298.                 $repairItem->setPriceQty($this->pricePaint);
  299.             }
  300.             $repairItem->setPriceSum($repairItem->getPriceQty() * $repairItem->getQty());
  301.             //XXX NEED TO FIX THE OTHER TYPE'S
  302.             $repairItem->setRepair($this);
  303.             $this->repairItems[] = $repairItem;
  304.         }
  305.         return $this;
  306.     }
  307.     public function removeRepairPaintItem(RepairItems $repairItem): self
  308.     {
  309.         if ($this->repairItems->removeElement($repairItem)) {
  310.             // set the owning side to null (unless already changed)
  311.             /*if ($repairItem->getRepair() === $this) {
  312.                 $repairItem->setRepair(null);
  313.             }*/
  314.         }
  315.         return $this;
  316.     }
  317.     /**
  318.      * @return Collection|RepairItems[]
  319.      */
  320.     public function getRepairAssemblyItems(): Collection
  321.     {
  322.         $criteria = Criteria::create();
  323.         $criteria->where(Criteria::expr()->eq('type', RepairItems::ASSEMBLY));
  324.         return $this->repairItems->matching($criteria);
  325.     }
  326.     public function addRepairAssemblyItem(RepairItems $repairItem): self
  327.     {
  328.         if (!$this->repairItems->contains($repairItem)) {
  329.             $repairItem->setType(RepairItems::ASSEMBLY);
  330.             if ($this->getPriceAssembly() !== null) {
  331.                 $repairItem->setPriceQty($this->priceAssembly);
  332.             }
  333.             $repairItem->setRepair($this);
  334.             $this->repairItems[] = $repairItem;
  335.         }
  336.         return $this;
  337.     }
  338.     public function removeRepairAssemblyItem(RepairItems $repairItem): self
  339.     {
  340.         if ($this->repairItems->removeElement($repairItem)) {
  341.             // set the owning side to null (unless already changed)
  342.             if ($repairItem->getRepair() === $this) {
  343.                 $repairItem->setRepair(null);
  344.             }
  345.         }
  346.         return $this;
  347.     }
  348.     /**
  349.      * @return Collection|RepairItems[]
  350.      */
  351.     public function getRepairBodyguardItems(): Collection
  352.     {
  353.         $criteria = Criteria::create();
  354.         $criteria->where(Criteria::expr()->eq('type', RepairItems::BODYGUARD));
  355.         return $this->repairItems->matching($criteria);
  356.     }
  357.     public function addRepairBodyguardItem(RepairItems $repairItem): self
  358.     {
  359.         if (!$this->repairItems->contains($repairItem)) {
  360.             $repairItem->setType(RepairItems::BODYGUARD);
  361.             if ($this->getPriceBodyguard() !== null) {
  362.                 $repairItem->setPriceQty($this->priceBodyguard);
  363.             }
  364.             $repairItem->setRepair($this);
  365.             $this->repairItems[] = $repairItem;
  366.         }
  367.         return $this;
  368.     }
  369.     public function removeRepairBodyguardItem(RepairItems $repairItem): self
  370.     {
  371.         if ($this->repairItems->removeElement($repairItem)) {
  372.             // set the owning side to null (unless already changed)
  373.             if ($repairItem->getRepair() === $this) {
  374.                 $repairItem->setRepair(null);
  375.             }
  376.         }
  377.         return $this;
  378.     }
  379.     /**
  380.      * @return Collection|RepairItems[]
  381.      */
  382.     public function getRepairOtherItems(): Collection
  383.     {
  384.         $criteria = Criteria::create();
  385.         $criteria->where(Criteria::expr()->eq('type', RepairItems::OTHER));
  386.         return $this->repairItems->matching($criteria);
  387.     }
  388.     public function addRepairOtherItem(RepairItems $repairItem): self
  389.     {
  390.         if (!$this->repairItems->contains($repairItem)) {
  391.             $repairItem->setType(RepairItems::OTHER);
  392.             $repairItem->setRepair($this);
  393.             $this->repairItems[] = $repairItem;
  394.         }
  395.         return $this;
  396.     }
  397.     public function removeRepairOtherItem(RepairItems $repairItem): self
  398.     {
  399.         if ($this->repairItems->removeElement($repairItem)) {
  400.             // set the owning side to null (unless already changed)
  401.             if ($repairItem->getRepair() === $this) {
  402.                 $repairItem->setRepair(null);
  403.             }
  404.         }
  405.         return $this;
  406.     }
  407.     /**
  408.      * @return Collection|RepairItems[]
  409.      */
  410.     public function getRepairMaterialItems(): Collection
  411.     {
  412.         $criteria = Criteria::create();
  413.         $criteria->where(Criteria::expr()->eq('type', RepairItems::MATERIAL));
  414.         return $this->repairItems->matching($criteria);
  415.     }
  416.     public function addRepairMaterialItem(RepairItems $repairItem): self
  417.     {
  418.         if (!$this->repairItems->contains($repairItem)) {
  419.             $repairItem->setType(RepairItems::MATERIAL);
  420.             $repairItem->setRepair($this);
  421.             $this->repairItems[] = $repairItem;
  422.         }
  423.         return $this;
  424.     }
  425.     public function removeRepairMaterialItem(RepairItems $repairItem): self
  426.     {
  427.         if ($this->repairItems->removeElement($repairItem)) {
  428.             // set the owning side to null (unless already changed)
  429.             if ($repairItem->getRepair() === $this) {
  430.                 $repairItem->setRepair(null);
  431.             }
  432.         }
  433.         return $this;
  434.     }
  435.     /**
  436.      * @return Collection|Attachment[]
  437.      */
  438.     public function getAttachments(): Collection
  439.     {
  440.         return $this->attachments;
  441.     }
  442.     public function addAttachment(Attachment $photo): self
  443.     {
  444.         if (!$this->attachments->contains($photo)) {
  445.             $photo->setRepair($this);
  446.             $this->attachments[] = $photo;
  447.         }
  448.         return $this;
  449.     }
  450.     public function removeAttachment(Attachment $photo): self
  451.     {
  452.         if ($this->attachments->removeElement($photo)) {
  453.             // set the owning side to null (unless already changed)
  454.             if ($photo->getRepair() === $this) {
  455.                 $photo->setRepair(null);
  456.             }
  457.         }
  458.         return $this;
  459.     }
  460.     public function getPriceBodyguard(): ?int
  461.     {
  462.         return $this->priceBodyguard;
  463.     }
  464.     public function setPriceBodyguard(?int $priceBodyguard): self
  465.     {
  466.         $this->priceBodyguard = $priceBodyguard;
  467.         return $this;
  468.     }
  469.     public function getPricePaint(): ?int
  470.     {
  471.         return $this->pricePaint;
  472.     }
  473.     public function setPricePaint(?int $pricePaint): self
  474.     {
  475.         $this->pricePaint = $pricePaint;
  476.         return $this;
  477.     }
  478.     public function getPriceAssembly(): ?int
  479.     {
  480.         return $this->priceAssembly;
  481.     }
  482.     public function setPriceAssembly(?int $priceAssembly): self
  483.     {
  484.         $this->priceAssembly = $priceAssembly;
  485.         return $this;
  486.     }
  487.     public function __toString()
  488.     {
  489.         $title = $this->title ? ' - ' . $this->title : ' ';
  490.         $start = $this->getStart() ? " - " . $this->getStart()->format('Ymd') : ' ';
  491.         $plate = $this->getCar() ? $this->getCar()->getPlateNumber() : 'No vehicle associated';
  492.         $km = $this->getKm() ? ' - ' . $this->getKm() . 'km' : ' ';
  493.         return $plate . $title . $km . $start;
  494.     }
  495.     public function rowCss($days = 30)
  496.     {
  497.         $now = new \DateTime();
  498.         if ($this->start) {
  499.             $nd = \DateTime::createFromFormat("Y-m-d", date('Y-m-d', strtotime($this->start->format('Y-m-d') . "+$days days")));
  500.             if ($this->finish == null && $nd < $now) {
  501.                 return "alert alert-warning";
  502.             } else if ($this->finish == null) {
  503.                 return "alert alert-success";
  504.             }
  505.         }
  506.         return "";
  507.     }
  508.     public function getSumPaint(): ?int
  509.     {
  510.         return $this->sumPaint;
  511.     }
  512.     public function setSumPaint(?int $sumPaint): self
  513.     {
  514.         $this->sumPaint = $sumPaint;
  515.         return $this;
  516.     }
  517.     public function getSumBodyguard(): ?int
  518.     {
  519.         return $this->sumBodyguard;
  520.     }
  521.     public function setSumBodyguard(?int $sumBodyguard): self
  522.     {
  523.         $this->sumBodyguard = $sumBodyguard;
  524.         return $this;
  525.     }
  526.     public function getSumAssembly(): ?int
  527.     {
  528.         return $this->sumAssembly;
  529.     }
  530.     public function setSumAssembly(?int $sumAssembly): self
  531.     {
  532.         $this->sumAssembly = $sumAssembly;
  533.         return $this;
  534.     }
  535.     public function getSumOther(): ?int
  536.     {
  537.         return $this->sumOther;
  538.     }
  539.     public function setSumOther(?int $sumOther): self
  540.     {
  541.         $this->sumOther = $sumOther;
  542.         return $this;
  543.     }
  544.     public function getSumMaterial(): ?int
  545.     {
  546.         return $this->sumMaterial;
  547.     }
  548.     public function setSumMaterial(?int $sumMaterial): self
  549.     {
  550.         $this->sumMaterial = $sumMaterial;
  551.         return $this;
  552.     }
  553.     public function numOfAttachments()
  554.     {
  555.         return $this->attachments ? count($this->attachments) : 0;
  556.     }
  557.     public function getModified(): ?\DateTimeInterface
  558.     {
  559.         return $this->modified;
  560.     }
  561.     public function setModified(\DateTimeInterface $modified): self
  562.     {
  563.         $this->modified = $modified;
  564.         return $this;
  565.     }
  566.     public function getTaxPrice()
  567.     {
  568.         if ($this->getPriceSumBr() > $this->getPriceSum()) {
  569.             return $this->getPriceSumBr() - $this->getPriceSum();
  570.         }
  571.         return 0;
  572.     }
  573.     /**
  574.      * @return Collection<int, InventoryItems>
  575.      */
  576.     public function getInventoryItem(): Collection
  577.     {
  578.         return $this->inventoryItem;
  579.     }
  580.     public function addInventoryItem(InventoryItems $inventoryItem): self
  581.     {
  582.         if (!$this->inventoryItem->contains($inventoryItem)) {
  583.             $this->inventoryItem[] = $inventoryItem;
  584.             $inventoryItem->setRepairs($this);
  585.         }
  586.         return $this;
  587.     }
  588.     public function removeInventoryItem(InventoryItems $inventoryItem): self
  589.     {
  590.         if ($this->inventoryItem->removeElement($inventoryItem)) {
  591.             // set the owning side to null (unless already changed)
  592.             if ($inventoryItem->getRepairs() === $this) {
  593.                 $inventoryItem->setRepairs(null);
  594.             }
  595.         }
  596.         return $this;
  597.     }
  598. }