<?php
/**
* Copyright (c) 2019, MND Next GmbH - www.mndnext.de
*/
namespace App\Entity;
use App\Entity\WinWOP\License;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Intl\Intl;
/**
* @ORM\Entity
* @ORM\HasLifecycleCallbacks()
* @ORM\Table(name="machines")
*/
class Machine
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
* @ORM\Column(name="serialnumber", type="string", length=190, nullable=false)
* @Assert\NotBlank(message="Bitte geben Sie einen Seriennummer ein.")
*/
private $serial;
/**
* @var string
* @ORM\Column(name="name", type="string", length=255, nullable=true)
*/
private $name;
/**
* @var string
* @ORM\Column(name="control", type="string", length=255, nullable=true)
*/
private $control;
/**
* @var string
* @ORM\Column(name="manufacturer_name", type="string", length=255, nullable=true)
*/
private $manufacturerName;
/**
* @ORM\ManyToOne(targetEntity="Company", inversedBy="machines", cascade={"persist"})
*/
private $company;
/**
* @var \DateTime
* @ORM\Column(name="launch", type="datetime", nullable=false)
*/
private $launch;
/**
* @var string
* @ORM\Column(name="smc_name", type="string", length=255, nullable=true)
*/
private $smc_name;
/**
* @var \DateTime
* @ORM\Column(name="smc_signing", type="date", nullable=true)
*/
private $smc_signing;
/**
* @var \DateTime
* @ORM\Column(name="smc_begin", type="date", nullable=true)
*/
private $smc_begin;
/**
* @var \DateTime
* @ORM\Column(name="smc_termination", type="date", nullable=true)
*/
private $smc_termination;
/**
* @ORM\OneToMany(targetEntity="App\Entity\WinWOP\License", mappedBy="machine", cascade={"persist"})
* @ORM\OrderBy({"created" = "DESC"})
*/
private $licenses;
/**
* @ORM\OneToOne(targetEntity="App\Entity\WinWOP\LicenseRequest", mappedBy="machine", cascade={"persist"})
*/
private $license_request;
/**
* @ORM\OneToOne(targetEntity="App\Entity\WinWOP\ModulesRequest", mappedBy="machine", cascade={"persist"})
*/
private $modules_request;
/**
* @ORM\OneToOne(targetEntity="App\Entity\WinWOP\SmcRequest", mappedBy="machine", cascade={"persist"})
*/
private $smc_request;
/**
* Constructor
*/
public function __construct()
{
$this->licenses = new \Doctrine\Common\Collections\ArrayCollection();
$this->launch = new \DateTime();
}
public function getId()
{
return $this->id;
}
public function setName($name)
{
$this->name = $name;
return $this;
}
public function getName()
{
return $this->name;
}
public function setSerial($serial)
{
$this->serial = $serial;
return $this;
}
public function getSerial()
{
return $this->serial;
}
public function setControl($control)
{
$this->control = $control;
return $this;
}
public function getControl()
{
return $this->control;
}
public function setManufacturerName($name)
{
$this->manufacturerName = $name;
return $this;
}
public function getManufacturerName()
{
return $this->manufacturerName;
}
/**
* get last used licensenumber
* @return string
*/
public function getLicensenumber()
{
if ($this->getLicenseRequest()) {
return $this->getLicenseRequest()->getLicenseNumber();
}
$license = $this->getCurrentLicense();
if ($license) {
return $license->getNumber();
}
return '';
}
public function setCompany(Company $company = null)
{
$this->company = $company;
return $this;
}
/**
* Get company
*
* @return Company|null
*/
public function getCompany()
{
return $this->company;
}
public function setSmcName($name)
{
$this->smc_name = $name;
return $this;
}
public function getSmcName()
{
return $this->smc_name;
}
public function setSmcSigning($dateTime)
{
$this->smc_signing = $dateTime;
return $this;
}
public function getSmcSigning()
{
return $this->smc_signing;
}
public function setSmcBegin($dateTime)
{
$this->smc_begin = $dateTime;
return $this;
}
public function getSmcBegin()
{
return $this->smc_begin;
}
public function setSmcTermination($dateTime)
{
$this->smc_termination = $dateTime;
return $this;
}
public function getSmcTermination()
{
return $this->smc_termination;
}
public function setSmcRequest($request)
{
$this->smc_request = $request;
return $this;
}
public function getSmcRequest()
{
return $this->smc_request;
}
public function setModulesRequest($request)
{
$this->modules_request = $request;
return $this;
}
/**
* return if machine has active software maintenance contract
*/
public function hasSmc()
{
$now = new \DateTime();
if (!empty($this->smc_begin) && $this->smc_begin <= $now) {
if (empty($this->smc_termination) || $this->smc_termination >= $now) {
return true;
}
}
return false;
}
public function getModulesRequest()
{
return $this->modules_request;
}
public function setLicenseRequest($request)
{
$this->license_request = $request;
return $this;
}
public function getLicenseRequest()
{
return $this->license_request;
}
public function setLaunch($launch)
{
$this->launch = $launch;
return $this;
}
public function getLaunch()
{
return $this->launch;
}
/**
* @return Collection|WinWOP\License[]
*/
public function getLicenses() : Collection
{
return $this->licenses;
}
public function addLicense(License $license)
{
if (!$this->licenses->contains($license)) {
$this->licenses->add($license);
$license->setMachine($this);
}
}
public function removeLicense(License $license)
{
//license removal not allowed!
}
/**
* @return License|null
*/
public function getCurrentLicense() : ?License
{
$license = $this->licenses->first();
if ($license) {
return $license;
}
return null;
}
/**
* @return Collection|WinWOP\Module[]|null
*/
public function getCurrentLicensedModules() : ?Collection
{
if ($this->getCurrentLicense()) {
return $this->getCurrentLicense()->getModules();
}
return null;
}
public function __toString()
{
return $this->getSerial();
}
}