<?php
namespace App\Entity;
use App\Repository\UnitRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
#[UniqueEntity(fields: "code", message: "Ya existe una sucursal registrada con este código")]
#[ORM\Entity(repositoryClass: UnitRepository::class)]
#[ORM\Table(name: '`unit`')]
class Unit
{
#[ORM\Id]
#[ORM\GeneratedValue(strategy:"AUTO")]
#[ORM\Column(type: "integer")]
protected ?int $id = null;
#[ORM\Column(type: "boolean")]
protected $enabled = true;
#[ORM\Column(type: "string")]
protected $name;
#[ORM\Column(type: "string")]
protected $code;
#[ORM\Column(type: "string")]
protected $costCenter;
#[ORM\ManyToOne(targetEntity:"App\Entity\City")]
#[ORM\JoinColumn(nullable: true, onDelete: "SET NULL")]
protected $city;
#[ORM\Column(type: "string")]
protected $address;
public function getId()
{
return $this->id;
}
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
}
public function getCode()
{
return $this->code;
}
public function setCode($code)
{
$this->code = $code;
}
public function getCostCenter()
{
return $this->costCenter;
}
public function setCostCenter($costCenter)
{
$this->costCenter = $costCenter;
}
public function getCity()
{
return $this->city;
}
public function setCity($city)
{
$this->city = $city;
}
public function getAddress()
{
return $this->address;
}
public function getFullAddress()
{
return sprintf('%s, %s, %s', $this->address, $this->getCity(), $this->getCity()->getParent());
}
public function setAddress($address)
{
$this->address = $address;
}
public function __toString()
{
return sprintf('%s - %s', $this->code, $this->name);
}
public function getEnabled()
{
return $this->enabled;
}
public function setEnabled($enabled)
{
$this->enabled = $enabled;
}
public function getCostCenterSucursal()
{
return sprintf('%s- %s- %s', $this->code, $this->name, $this->costCenter);
}
}