src/Entity/Cars.php line 21

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. use Doctrine\ORM\Mapping\Index;
  8. use function Symfony\Component\Translation\t;
  9. /**
  10.  * Cars
  11.  *
  12.  * @ORM\Table(name="cars",indexes={
  13.  *     @Index(name="plate_number",columns={"plate_number"}),
  14.  *     @Index(name="owner_name",columns={"owner_name"})
  15.  * })
  16.  * @ORM\Entity
  17.  */
  18. class Cars
  19. {
  20.     /**
  21.      * @var int
  22.      *
  23.      * @ORM\Column(name="id", type="integer", nullable=false)
  24.      * @ORM\Id
  25.      * @ORM\GeneratedValue(strategy="IDENTITY")
  26.      */
  27.     private $id;
  28.     /**
  29.      * @var string
  30.      *
  31.      * @ORM\Column(name="owner_name", type="string", length=250, nullable=true, options={"comment"="Tulajdonos neve"})
  32.      */
  33.     private $ownerName;
  34.     /**
  35.      * @var string|null
  36.      *
  37.      * @ORM\Column(name="owner_address", type="string", length=250, nullable=true, options={"comment"="Lakcím"})
  38.      */
  39.     private $ownerAddress;
  40.     /**
  41.      * @var string
  42.      *
  43.      * @ORM\Column(name="owner_phone", type="string", length=30, nullable=true, options={"comment"="Telefonszám"})
  44.      */
  45.     private $ownerPhone;
  46.     /**
  47.      * @var string|null
  48.      *
  49.      * @ORM\Column(name="owner_mail", type="string", length=100, nullable=true, options={"comment"="Email cím"})
  50.      */
  51.     private $ownerMail;
  52.     /**
  53.      * @var int
  54.      *
  55.      * @ORM\Column(name="owner_req_mail", type="integer", nullable=true, options={"comment"="Kérek emailt"})
  56.      */
  57.     private $ownerReqMail;
  58.     /**
  59.      * @var string
  60.      *
  61.      * @ORM\Column(name="plate_number", type="string", length=20, nullable=true, options={"comment"="Rendszám"})
  62.      */
  63.     private $plateNumber;
  64.     /**
  65.      * @var string
  66.      *
  67.      * @ORM\Column(name="manufacturer", type="string", length=250, nullable=false, options={"comment"="Gyártmány"})
  68.      */
  69.     private $manufacturer;
  70.     /**
  71.      * @var string
  72.      *
  73.      * @ORM\Column(name="type", type="string", length=250, nullable=true, options={"comment"="Típus"})
  74.      */
  75.     private $type;
  76.     /**
  77.      * @var int
  78.      *
  79.      * @ORM\Column(name="vintage", type="integer", nullable=true, options={"comment"="Évjárat"})
  80.      */
  81.     private $vintage;
  82.     /**
  83.      * @var string
  84.      *
  85.      * @ORM\Column(name="fuel", type="string", length=20, nullable=true, options={"comment"="Üzemanyag"})
  86.      */
  87.     private $fuel;
  88.     /**
  89.      * @var int|null
  90.      *
  91.      * @ORM\Column(name="cylinder_capacity", type="integer", nullable=true, options={"comment"="Hengerürtartalom"})
  92.      */
  93.     private $cylinderCapacity;
  94.     /**
  95.      * @var string|null
  96.      *
  97.      * @ORM\Column(name="vin_code", type="string", length=40, nullable=true, options={"comment"="Alvázszám"})
  98.      */
  99.     private $vinCode;
  100.     /**
  101.      * @var string|null
  102.      *
  103.      * @ORM\Column(name="motor_code", type="string", length=40, nullable=true, options={"comment"="Motorszám"})
  104.      */
  105.     private $motorCode;
  106.     /**
  107.      * @var int|null
  108.      *
  109.      * @ORM\Column(name="kw", type="integer", nullable=true, options={"comment"="Teljesítmény"})
  110.      */
  111.     private $kw;
  112.     /**
  113.      * @var string|null
  114.      *
  115.      * @ORM\Column(name="traffic", type="string", length=50, nullable=true, options={"comment"="Forgalmi"})
  116.      */
  117.     private $traffic;
  118.     /**
  119.      * @var \DateTime|null
  120.      *
  121.      * @ORM\Column(name="technical_date", type="date", nullable=true, options={"comment"="Műszakivizsga"})
  122.      */
  123.     private $technicalDate;
  124.     /**
  125.      * @var string|null
  126.      *
  127.      * @ORM\Column(name="note", type="text", length=65535, nullable=true, options={"comment"="Megjegyzés"})
  128.      */
  129.     private $note;
  130.     /**
  131.      * @var \DateTime
  132.      *
  133.      * @ORM\Column(name="created", type="datetime", nullable=false, options={"comment"="Létrehozva"})
  134.      */
  135.     private $created;
  136.     /**
  137.      * @var \DateTime
  138.      *
  139.      * @ORM\Column(name="modified", type="datetime", nullable=true, options={"comment"="Módosítva"})
  140.      */
  141.     private $modified;
  142.     /**
  143.      * @ORM\OneToMany(targetEntity=PdfFiles::class, mappedBy="car", cascade={"persist"},orphanRemoval=true)
  144.      */
  145.     public $pdfs;
  146.     /**
  147.      * @ORM\OneToMany(targetEntity=Repairs::class, mappedBy="car")
  148.      */
  149.     public $repairs;
  150.     private $settings;
  151.     public static $fuelTypes = [
  152.         'diesel' => 'Diesel',
  153.         'benzin' => 'Petrol',
  154.         'gas' => 'Autogas',
  155.         'electric' => 'Electric',
  156.         'hybrid' => 'Hybrid',
  157.     ];
  158.     public static function getFuelTypes()
  159.     {
  160.         $types = [];
  161.         foreach (Cars::$fuelTypes as $key => $value) {
  162.             $types[$key] = t($value);
  163.         }
  164.         return $types;
  165.     }
  166.     /**
  167.      * @ORM\OneToMany(targetEntity=Events::class, mappedBy="car_id")
  168.      */
  169.     private $events;
  170.     /**
  171.      * @ORM\Column(type="datetime", nullable=true)
  172.      */
  173.     private $technical_mail_sended;
  174.     /**
  175.      * @ORM\OneToMany(targetEntity=CarAttachment::class, mappedBy="car", cascade={"persist"}, orphanRemoval=true)
  176.      */
  177.     private $attachments;
  178.     /**
  179.      * @ORM\ManyToOne(targetEntity=Group::class, inversedBy="cars")
  180.      */
  181.     private $parentGroup;
  182.     /**
  183.      * @ORM\ManyToOne(targetEntity=CarOwner::class,  cascade={"persist"}, inversedBy="cars")
  184.      */
  185.     private $owners;
  186.     /**
  187.      * @ORM\ManyToOne(targetEntity=CarOwner::class,  cascade={"persist"}, inversedBy="cars")
  188.      */
  189.     private $contact;
  190.     /**
  191.      * @ORM\Column(type="string", length=255, nullable=true)
  192.      */
  193.     private $insurance;
  194.     /**
  195.      * @ORM\Column(type="date", nullable=true)
  196.      */
  197.     private $insurance_duedate;
  198.     public function __construct()
  199.     {
  200.         $this->created = new \DateTime();
  201.         $this->pdfFiles = new ArrayCollection();
  202.         $this->title = new ArrayCollection();
  203.         $this->attachments = new ArrayCollection();
  204.     }
  205.     public function getId(): ?int
  206.     {
  207.         return $this->id;
  208.     }
  209.     public function getOwnerName(): ?string
  210.     {
  211.         return $this->ownerName;
  212.     }
  213.     public function setOwnerName(string $ownerName): self
  214.     {
  215.         $this->ownerName = $ownerName;
  216.         return $this;
  217.     }
  218.     public function getOwnerAddress(): ?string
  219.     {
  220.         return $this->ownerAddress;
  221.     }
  222.     public function setOwnerAddress(?string $ownerAddress): self
  223.     {
  224.         $this->ownerAddress = $ownerAddress;
  225.         return $this;
  226.     }
  227.     public function getOwnerPhone(): ?string
  228.     {
  229.         return $this->ownerPhone;
  230.     }
  231.     public function setOwnerPhone(?string $ownerPhone): self
  232.     {
  233.         $this->ownerPhone = $ownerPhone;
  234.         return $this;
  235.     }
  236.     public function getOwnerMail(): ?string
  237.     {
  238.         return $this->ownerMail;
  239.     }
  240.     public function setOwnerMail(?string $ownerMail): self
  241.     {
  242.         $this->ownerMail = $ownerMail;
  243.         return $this;
  244.     }
  245.     public function getOwnerReqMail(): ?int
  246.     {
  247.         return $this->ownerReqMail == null ? 0 : $this->ownerReqMail;
  248.     }
  249.     public function setOwnerReqMail(int $ownerReqMail): self
  250.     {
  251.         $this->ownerReqMail = $ownerReqMail;
  252.         return $this;
  253.     }
  254.     public function getPlateNumber(): ?string
  255.     {
  256.         return $this->plateNumber;
  257.     }
  258.     public function setPlateNumber(string $plateNumber): self
  259.     {
  260.         $this->plateNumber = strtoupper($plateNumber);
  261.         return $this;
  262.     }
  263.     public function getManufacturer(): ?string
  264.     {
  265.         return $this->manufacturer;
  266.     }
  267.     public function setManufacturer(string $manufacturer): self
  268.     {
  269.         $this->manufacturer = $manufacturer;
  270.         return $this;
  271.     }
  272.     public function getType(): ?string
  273.     {
  274.         return $this->type;
  275.     }
  276.     public function setType(?string $type): self
  277.     {
  278.         $this->type = $type;
  279.         return $this;
  280.     }
  281.     public function getVintage(): ?int
  282.     {
  283.         return $this->vintage;
  284.     }
  285.     public function setVintage(?int $vintage): self
  286.     {
  287.         $this->vintage = $vintage;
  288.         return $this;
  289.     }
  290.     public function getFuel(): ?string
  291.     {
  292.         return $this->fuel;
  293.     }
  294.     public function setFuel(string $fuel): self
  295.     {
  296.         $this->fuel = $fuel;
  297.         return $this;
  298.     }
  299.     public function getCylinderCapacity(): ?int
  300.     {
  301.         return $this->cylinderCapacity;
  302.     }
  303.     public function setCylinderCapacity(?int $cylinderCapacity): self
  304.     {
  305.         $this->cylinderCapacity = $cylinderCapacity;
  306.         return $this;
  307.     }
  308.     public function getVinCode(): ?string
  309.     {
  310.         return $this->vinCode;
  311.     }
  312.     public function setVinCode(?string $vinCode): self
  313.     {
  314.         $this->vinCode = $vinCode;
  315.         return $this;
  316.     }
  317.     public function getMotorCode(): ?string
  318.     {
  319.         return $this->motorCode;
  320.     }
  321.     public function setMotorCode(?string $motorCode): self
  322.     {
  323.         $this->motorCode = $motorCode;
  324.         return $this;
  325.     }
  326.     public function getKw(): ?int
  327.     {
  328.         return $this->kw;
  329.     }
  330.     public function setKw(?int $kw): self
  331.     {
  332.         $this->kw = $kw;
  333.         return $this;
  334.     }
  335.     public function getTraffic(): ?string
  336.     {
  337.         return $this->traffic;
  338.     }
  339.     public function setTraffic(?string $traffic): self
  340.     {
  341.         $this->traffic = $traffic;
  342.         return $this;
  343.     }
  344.     public function getTechnicalDate(): ?\DateTimeInterface
  345.     {
  346.         return $this->technicalDate;
  347.     }
  348.     public function setTechnicalDate(?\DateTimeInterface $technicalDate): self
  349.     {
  350.         if ($technicalDate && $this->technicalDate && $technicalDate->format('Y-m-d') != $this->technicalDate->format('Y-m-d')) {
  351.             $this->technical_mail_sended = null;
  352.         }
  353.         $this->technicalDate = $technicalDate;
  354.         return $this;
  355.     }
  356.     public function getNote(): ?string
  357.     {
  358.         return $this->note;
  359.     }
  360.     public function setNote(?string $note): self
  361.     {
  362.         $this->note = $note;
  363.         return $this;
  364.     }
  365.     public function getCreated(): ?\DateTimeInterface
  366.     {
  367.         return $this->created;
  368.     }
  369.     public function setCreated(\DateTimeInterface $created): self
  370.     {
  371.         $this->created = $created;
  372.         return $this;
  373.     }
  374.     public function __toString()
  375.     {
  376.         if ($this->getPlateNumber()) {
  377.             return (string)$this->getPlateNumber() . " - " . $this->getManufacturer() . " " . $this->getType() . " (" . $this->getVintage() . ")";
  378.         } else {
  379.             return t('No Plate number') . " - " . $this->getManufacturer() . " " . $this->getType();
  380.         }
  381.     }
  382.     // private function addToDate($field, $str = " + 1 years")
  383.     // {
  384.     //     $this->$field = \DateTime::createFromFormat("Y-m-d", date('Y-m-d', strtotime($this->$field->format('Y-m-d') . $str)));
  385.     // }
  386.     public function rowCss($days = 60)
  387.     {
  388.         $now = new \DateTime();
  389.         if ($this->technicalDate) {
  390.             $nd = \DateTime::createFromFormat("Y-m-d", date('Y-m-d', strtotime($this->technicalDate->format('Y-m-d') . "-$days days")));
  391.             if ($this->technicalDate < $now) {
  392.                 return "alert alert-danger";
  393.             } else if ($nd < $now) {
  394.                 return "alert alert-warning";
  395.             }
  396.         }
  397.         return "";
  398.     }
  399.     /**
  400.      * @return Collection|RepairItems[]
  401.      */
  402.     public function getWorkPdfs(): Collection
  403.     {
  404.         $criteria = Criteria::create();
  405.         $criteria->where(Criteria::expr()->eq('type', 'Elszámolás'));
  406.         $criteria->orderBy(['id' => 'desc']);
  407.        // $criteria->setMaxResults(5);
  408.         return $this->pdfs->matching($criteria);
  409.     }
  410.     /**
  411.      * @return Collection|RepairItems[]
  412.      */
  413.     public function getQuotePdfs(): Collection
  414.     {
  415.         $criteria = Criteria::create();
  416.         $criteria->where(Criteria::expr()->eq('type', 'Ajánlat'));
  417.         $criteria->orderBy(['id' => 'desc']);
  418.         //$criteria->setMaxResults(5);
  419.         return $this->pdfs->matching($criteria);
  420.     }
  421.     public function getLastKm()
  422.     {
  423.         $criteria = Criteria::create();
  424.         $criteria->orderBy(['km' => 'desc']);
  425.         $criteria->setMaxResults(1);
  426.         $row = $this->repairs->matching($criteria);
  427.         return count($row) > 0 ? $row[0]->getKm() : null;
  428.     }
  429.     public function getModified(): ?\DateTimeInterface
  430.     {
  431.         return $this->modified;
  432.     }
  433.     /**
  434.      * @return Collection|Events[]
  435.      */
  436.     public function getTitle(): Collection
  437.     {
  438.         return $this->title;
  439.     }
  440.     public function addTitle(Events $title): self
  441.     {
  442.         if (!$this->title->contains($title)) {
  443.             $this->title[] = $title;
  444.             $title->setCarId($this);
  445.         }
  446.         return $this;
  447.     }
  448.     public function removeTitle(Events $title): self
  449.     {
  450.         if ($this->title->removeElement($title)) {
  451.             // set the owning side to null (unless already changed)
  452.             if ($title->getCarId() === $this) {
  453.                 $title->setCarId(null);
  454.             }
  455.         }
  456.         return $this;
  457.     }
  458.     public function getTechnicalMailSended(): ?\DateTimeInterface
  459.     {
  460.         return $this->technical_mail_sended;
  461.     }
  462.     public function setTechnicalMailSended(?\DateTimeInterface $technical_mail_sended): self
  463.     {
  464.         $this->technical_mail_sended = $technical_mail_sended;
  465.         return $this;
  466.     }
  467.     /**
  468.      * @return Collection<int, CarAttachment>
  469.      */
  470.     public function getCarAttachments(): Collection
  471.     {
  472.         return $this->attachments;
  473.     }
  474.     public function addCarAttachment(CarAttachment $attachment): self
  475.     {
  476.         if (!$this->attachments->contains($attachment)) {
  477.             $this->attachments[] = $attachment;
  478.             $attachment->setCar($this);
  479.         }
  480.         return $this;
  481.     }
  482.     public function removeCarAttachment(CarAttachment $attachment): self
  483.     {
  484.         if ($this->attachments->removeElement($attachment)) {
  485.             // set the owning side to null (unless already changed)
  486.             if ($attachment->getCar() === $this) {
  487.                 $attachment->setCar(null);
  488.             }
  489.         }
  490.         return $this;
  491.     }
  492.     public function getParentGroup(): ?Group
  493.     {
  494.         return $this->parentGroup;
  495.     }
  496.     public function setParentGroup(?Group $parentGroup): self
  497.     {
  498.         $this->parentGroup = $parentGroup;
  499.         return $this;
  500.     }
  501.     public function getOwners(): ?CarOwner
  502.     {
  503.         return $this->owners;
  504.     }
  505.     public function setOwners(?CarOwner $owners): self
  506.     {
  507.         $this->owners = $owners;
  508.         return $this;
  509.     }
  510.     public function getContact(): ?CarOwner
  511.     {
  512.         return $this->contact;
  513.     }
  514.     public function setContact(?CarOwner $contact): self
  515.     {
  516.         $this->contact = $contact;
  517.         return $this;
  518.     }
  519.     public function getInsurance(): ?string
  520.     {
  521.         return $this->insurance;
  522.     }
  523.     public function setInsurance(?string $insurance): self
  524.     {
  525.         $this->insurance = $insurance;
  526.         return $this;
  527.     }
  528.     public function getInsuranceDuedate(): ?\DateTimeInterface
  529.     {
  530.         return $this->insurance_duedate;
  531.     }
  532.     public function setInsuranceDuedate(?\DateTimeInterface $insurance_duedate): self
  533.     {
  534.         $this->insurance_duedate = $insurance_duedate;
  535.         return $this;
  536.     }
  537. }