<?php
namespace App\Entity;
use App\Repository\EmployeeRepository;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
use Tionvel\ImporterBundle\Validator as TionvelAssert;
/**
* @Serializer\ExclusionPolicy("ALL")
*/
#[UniqueEntity(fields: "username",message: "Ya existe un usuario o proveedor con este nombre")]
#[UniqueEntity(fields: "rut",message: "Ya existe un usuario o proveedor con este RUT")]
#[UniqueEntity(fields: "email",message: "Ya existe un usuario o proveedor con este email")]
#[ORM\Entity(repositoryClass: EmployeeRepository::class)]
#[ORM\Table(name: '`employee`')]
class Employee
{
/**
* @Serializer\Expose()
*/
#[ORM\Id]
#[ORM\GeneratedValue(strategy:"AUTO")]
#[ORM\Column(type: "integer")]
protected ?int $id = null;
#[ORM\OneToOne(mappedBy: "employee", targetEntity: "User", cascade: ['persist', 'remove'], fetch: "EAGER")]
#[ORM\JoinColumn(name: "user_id", referencedColumnName: "id", onDelete: "CASCADE")]
protected $user;
/**
* @Serializer\Expose()
*/
#[Assert\NotBlank(message: 'El Nombre no puede estar en blanco')]
#[ORM\Column(type: "string")]
protected $name;
/**
* @Serializer\Expose()
*/
#[Assert\NotBlank(message: 'El Apellido no puede estar en blanco')]
#[ORM\Column(type: "string")]
protected $lastName;
/**
* @Serializer\Expose()
*/
#[ORM\Column(type: "string", nullable: true)]
protected $secondLastName;
/**
* @Serializer\Expose()
*/
#[TionvelAssert\Rut]
#[Assert\NotBlank(message: 'El Rut no puede estar en blanco')]
#[ORM\Column(type: "string", length: 100, unique: true )]
protected $rut;
#[Assert\NotBlank(message: 'La sucursal no puede estar en blanco')]
#[ORM\ManyToOne(targetEntity:"Office", inversedBy:"employees")]
#[ORM\JoinColumn(name: "office_id", referencedColumnName: "id", nullable: true, onDelete: "SET NULL")]
protected $office;
/**
* @Serializer\Expose()
*/
#[Assert\Length(max: 32,maxMessage: 'Este campo no puede exceder los {{ limit }} caaracteres.')]
#[ORM\Column(type: "string", nullable: true)]
protected $phone;
#[Assert\Email(message: 'Ingresa un email vĂ¡lido.')]
#[Assert\NotBlank(message: 'El email no puede estar en blanco.')]
#[ORM\Column(type: "string", unique: true)]
protected $email;
#[Assert\NotBlank(message: 'El nombre de usuario no puede estar en blanco.')]
#[ORM\Column(type: "string", unique: true)]
protected $username;
#[ORM\Column(type: "string", nullable: true)]
protected $position;
#[ORM\Column(type: "boolean")]
protected $isAdmin = false;
#[ORM\Column(type: "boolean")]
protected $isFinances = false;
#[ORM\Column(type: "boolean")]
protected $isAcquisitions = false;
#[ORM\Column(type: "boolean")]
protected $isAcquisitionManager = false;
#[ORM\Column(type: "boolean")]
protected $isViewer = false;
#[ORM\Column(type: "boolean")]
protected $isRequester = false;
#[ORM\Column(type: "boolean")]
protected $isLegal = false;
#[ORM\Column(type: "boolean")]
protected $isCompras = false;
#[ORM\Column(type: "boolean")]
protected $isContractsViewer = false;
public function getId()
{
return $this->id;
}
public function setName($name)
{
$this->name = $name;
}
public function getName()
{
return $this->name;
}
public function setLastName($lastName)
{
$this->lastName = $lastName;
}
public function getLastName()
{
return $this->lastName;
}
public function setSecondLastName($secondLastName)
{
$this->secondLastName = $secondLastName;
}
public function getSecondLastName()
{
return $this->secondLastName;
}
public function setRut($rut)
{
$this->rut = $rut;
}
public function getRut()
{
return $this->rut;
}
public function setPhone($phone)
{
$this->phone = $phone;
}
public function getPhone()
{
return $this->phone;
}
public function getUser()
{
return $this->user;
}
public function getFullName()
{
return mb_convert_case(sprintf('%s %s %s', $this->name, $this->lastName, $this->secondLastName), MB_CASE_TITLE);
}
public function __toString()
{
return sprintf('%s %s', $this->rut, $this->getFullName());
}
public function setUser(User $user = null)
{
$this->user = $user;
}
public function setOffice(Office $office = null)
{
if ($this->office === $office) {
return;
}
$this->office = $office;
if (! is_null($office)) {
$office->addEmployee($this);
}
}
public function getOffice()
{
return $this->office;
}
public function getPosition()
{
return $this->position;
}
public function setPosition($position)
{
$this->position = $position;
}
public function getEmail()
{
return $this->email;
}
public function setEmail($email)
{
$this->email = $email;
}
public function getUsername()
{
return $this->username;
}
public function setUsername($username)
{
$this->username = $username;
}
public function isAdmin(): bool
{
return $this->isAdmin;
}
public function setIsAdmin(bool $isAdmin)
{
$this->isAdmin = $isAdmin;
}
public function isFinances(): bool
{
return $this->isFinances;
}
public function setIsFinances(bool $isFinances)
{
$this->isFinances = $isFinances;
}
public function isAcquisitions(): bool
{
return $this->isAcquisitions;
}
public function setIsAcquisitions(bool $isAcquisitions)
{
$this->isAcquisitions = $isAcquisitions;
}
public function isAcquisitionManager(): bool
{
return $this->isAcquisitionManager;
}
public function setIsAcquisitionManager(bool $isAm)
{
$this->isAcquisitionManager = $isAm;
}
public function isRequester(): bool
{
return $this->isRequester;
}
public function setIsRequester(bool $isRequester)
{
$this->isRequester = $isRequester;
}
public function isViewer(): bool
{
return $this->isViewer;
}
public function setIsViewer(bool $isViewer)
{
$this->isViewer = $isViewer;
}
/**
* @return bool
*/
public function isLegal(): bool
{
return $this->isLegal;
}
/**
* @param bool $isLegal
*/
public function setIsLegal(bool $isLegal)
{
$this->isLegal = $isLegal;
}
public function isCompras(): bool
{
return $this->isCompras;
}
public function setIsCompras(bool $isCompras): void
{
$this->isCompras = $isCompras;
}
public function isContractsViewer(): bool
{
return $this->isContractsViewer;
}
public function setIsContractsViewer(bool $isContractsViewer): void
{
$this->isContractsViewer = $isContractsViewer;
}
}