<?php
namespace App\Entity;
use App\Repository\SuministroRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity(repositoryClass=SuministroRepository::class)
* @UniqueEntity("cups")
*/
class Suministro
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $cups;
/**
* @ORM\ManyToOne(targetEntity=TipoVia::class)
* @ORM\JoinColumn(nullable=false)
*/
private $tipoVia;
/**
* @ORM\Column(type="string", length=255)
*/
private $nombreVia;
/**
* @ORM\Column(type="string", length=255)
*/
private $numeroDireccion;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $escalera;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $piso;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $puerta;
/**
* @ORM\Column(type="string", length=255)
*/
private $cp;
/**
* @ORM\Column(type="string", length=255)
*/
private $poblacion;
/**
* @ORM\Column(type="string", length=255)
*/
private $provincia;
/**
* @ORM\Column(type="decimal", precision=10, scale=5, nullable=true)
*/
private $potenciaP1;
/**
* @ORM\Column(type="decimal", precision=10, scale=5, nullable=true)
*/
private $potenciaP2;
/**
* @ORM\Column(type="decimal", precision=10, scale=5, nullable=true)
*/
private $potenciaP3;
/**
* @ORM\Column(type="decimal", precision=10, scale=5, nullable=true)
*/
private $potenciaP4;
/**
* @ORM\Column(type="decimal", precision=10, scale=5, nullable=true)
*/
private $potenciaP5;
/**
* @ORM\Column(type="decimal", precision=10, scale=5, nullable=true)
*/
private $potenciaP6;
/**
* @ORM\Column(type="decimal", precision=10, scale=5, nullable=true)
*/
private $alquilerContador;
/**
* @ORM\Column(type="integer")
*/
private $consumoAnual;
/**
* @ORM\OneToMany(targetEntity=Contrato::class, mappedBy="suministro")
*/
private $contratos;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $observaciones;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $maximetro;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $codigoContable;
/**
* @ORM\Column(type="decimal", precision=10, scale=5, nullable=true)
*/
private $alquilerContadorReal;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $direccionCompleta;
public function __construct()
{
$this->contratos = new ArrayCollection();
$this->updateDireccion();
}
public function getId(): ?int
{
return $this->id;
}
public function getCups(): ?string
{
return $this->cups;
}
public function setCups(string $cups): self
{
$this->cups = $cups;
return $this;
}
public function getTipoVia(): ?TipoVia
{
return $this->tipoVia;
}
public function setTipoVia(?TipoVia $tipoVia): self
{
$this->tipoVia = $tipoVia;
$this->updateDireccion();
return $this;
}
public function getNombreVia(): ?string
{
return $this->nombreVia;
}
public function setNombreVia(string $nombreVia): self
{
$this->nombreVia = $nombreVia;
$this->updateDireccion();
return $this;
}
public function getNumeroDireccion(): ?string
{
return $this->numeroDireccion;
}
public function setNumeroDireccion(string $numeroDireccion): self
{
$this->numeroDireccion = $numeroDireccion;
$this->updateDireccion();
return $this;
}
public function getEscalera(): ?string
{
return $this->escalera;
}
public function setEscalera(?string $escalera): self
{
$this->escalera = $escalera;
$this->updateDireccion();
return $this;
}
public function getPiso(): ?string
{
return $this->piso;
}
public function setPiso(?string $piso): self
{
$this->piso = $piso;
$this->updateDireccion();
return $this;
}
public function getPuerta(): ?string
{
return $this->puerta;
}
public function setPuerta(?string $puerta): self
{
$this->puerta = $puerta;
$this->updateDireccion();
return $this;
}
public function getCp(): ?string
{
return $this->cp;
}
public function setCp(string $cp): self
{
$this->cp = $cp;
return $this;
}
public function getPoblacion(): ?string
{
return $this->poblacion;
}
public function setPoblacion(string $poblacion): self
{
$this->poblacion = $poblacion;
$this->updateDireccion();
return $this;
}
public function getProvincia(): ?string
{
return $this->provincia;
}
public function setProvincia(string $provincia): self
{
$this->provincia = $provincia;
return $this;
}
public function getPotenciaP1(): ?string
{
return $this->potenciaP1;
}
public function setPotenciaP1(?string $potenciaP1): self
{
$this->potenciaP1 = $potenciaP1;
return $this;
}
public function getPotenciaP2(): ?string
{
return $this->potenciaP2;
}
public function setPotenciaP2(?string $potenciaP2): self
{
$this->potenciaP2 = $potenciaP2;
return $this;
}
public function getPotenciaP3(): ?string
{
return $this->potenciaP3;
}
public function setPotenciaP3(?string $potenciaP3): self
{
$this->potenciaP3 = $potenciaP3;
return $this;
}
public function getPotenciaP4(): ?string
{
return $this->potenciaP4;
}
public function setPotenciaP4(?string $potenciaP4): self
{
$this->potenciaP4 = $potenciaP4;
return $this;
}
public function getPotenciaP5(): ?string
{
return $this->potenciaP5;
}
public function setPotenciaP5(?string $potenciaP5): self
{
$this->potenciaP5 = $potenciaP5;
return $this;
}
public function getPotenciaP6(): ?string
{
return $this->potenciaP6;
}
public function setPotenciaP6(?string $potenciaP6): self
{
$this->potenciaP6 = $potenciaP6;
return $this;
}
public function getAlquilerContador(): ?string
{
return $this->alquilerContador;
}
public function setAlquilerContador(string $alquilerContador): self
{
$this->alquilerContador = $alquilerContador;
return $this;
}
public function getConsumoAnual(): ?int
{
return $this->consumoAnual;
}
public function setConsumoAnual(int $consumoAnual): self
{
$this->consumoAnual = $consumoAnual;
return $this;
}
/**
* @return Collection|Contrato[]
*/
public function getContratos(): Collection
{
return $this->contratos;
}
public function getContrato(): ?Contrato
{
$contratos=array_filter(
$this->contratos->toArray(),
function ($e) {
return $e->getEstado()->getId() == 1 ;
}
);
$contrato=end($contratos);
if(!$contrato){
return null;
}else{
return $contrato;
}
}
public function addContrato(Contrato $contrato): self
{
if (!$this->contratos->contains($contrato)) {
$this->contratos[] = $contrato;
$contrato->setSuministro($this);
}
return $this;
}
public function removeContrato(Contrato $contrato): self
{
if ($this->contratos->contains($contrato)) {
$this->contratos->removeElement($contrato);
// set the owning side to null (unless already changed)
if ($contrato->getSuministro() === $this) {
$contrato->setSuministro(null);
}
}
return $this;
}
public function __toString():?string
{
return $this->cups;
}
public function getDireccion():?string
{
$direccion=($this->tipoVia??new TipoVia())->getNombre().' '.$this->nombreVia.' '.$this->numeroDireccion;
if(!empty($this->escalera)){
$direccion.=', '.$this->escalera;
}
if(!empty($this->piso)){
$direccion.=', '.$this->piso;
}
if(!empty($this->puerta)){
$direccion.=', '.$this->puerta;
}
return $direccion;
}
public function getObservaciones(): ?string
{
return $this->observaciones;
}
public function setObservaciones(?string $observaciones): self
{
$this->observaciones = $observaciones;
return $this;
}
public function getMaximetro(): ?bool
{
return $this->maximetro;
}
public function setMaximetro(?bool $maximetro): self
{
$this->maximetro = $maximetro;
return $this;
}
public function getCodigoContable(): ?string
{
return $this->codigoContable;
}
public function setCodigoContable(?string $codigoContable): self
{
$this->codigoContable = $codigoContable;
return $this;
}
public function getAlquilerContadorReal(): ?string
{
return $this->alquilerContadorReal;
}
public function setAlquilerContadorReal(?string $alquilerContadorReal): self
{
$this->alquilerContadorReal = $alquilerContadorReal;
return $this;
}
public function getDireccionCompleta(): ?string
{
return $this->direccionCompleta;
}
public function updateDireccion(): self
{
$this->direccionCompleta = $this->getDireccion();
return $this;
}
}