<?php
namespace App\Entity;
use App\Repository\AgencyRepository;
use App\Repository\ConfigurationRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: AgencyRepository::class)]
#[ORM\Table(name: 'tb_agencies')]
#[ORM\HasLifecycleCallbacks]
class Agency
{
#[ORM\Id]
#[ORM\Column(type: "string", unique: true)]
private ?string $id;
#[ORM\Column(length: 50, unique: true)]
private ?string $code;
#[ORM\Column(length: 50, unique: true)]
private ?string $name;
#[ORM\Column(type: 'boolean', nullable: true)]
private ?bool $headOffice;
#[ORM\Column(type: 'datetime', nullable: false)]
private ?\DateTimeInterface $createdAt;
#[ORM\Column(type: 'datetime', nullable: true)]
private ?\DateTimeInterface $modifiedAt;
#[ORM\Column(type: 'boolean', nullable: false)]
private ?bool $activated;
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'agencies')]
private ?User $createdBy;
#[ORM\OneToMany(mappedBy: 'agency', targetEntity: AgencyAccount::class)]
private ?Collection $agencyAccounts;
#[ORM\OneToMany(mappedBy: 'agency', targetEntity: AgencyExtension::class)]
private ?Collection $agencyExtensions;
#[ORM\OneToMany(mappedBy: 'startingAgency', targetEntity: Transfert::class)]
private Collection $transferts;
public function __construct()
{
$this->agencyAccounts = new ArrayCollection();
$this->agencyExtensions = new ArrayCollection();
$this->createdAt = new \DateTime();
$this->transferts = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function setId(string $id): self
{
$this->id = $id;
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getHeadOffice(): ?bool
{
return $this->headOffice;
}
public function setHeadOffice(?bool $headOffice): self
{
$this->headOffice = $headOffice;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getModifiedAt(): ?\DateTimeInterface
{
return $this->modifiedAt;
}
public function setModifiedAt(?\DateTimeInterface $modifiedAt): self
{
$this->modifiedAt = $modifiedAt;
return $this;
}
public function getActivated(): ?bool
{
return $this->activated;
}
public function setActivated(?bool $activated): self
{
$this->activated = $activated;
return $this;
}
public function getCreatedBy(): ?User
{
return $this->createdBy;
}
public function setCreatedBy(?User $createdBy): self
{
$this->createdBy = $createdBy;
return $this;
}
/**
* @return Collection|AgencyAccount[]
*/
public function getAgencyAccounts(): Collection
{
return $this->agencyAccounts;
}
public function addAgencyAccount(AgencyAccount $agencyAccount): self
{
if (!$this->agencyAccounts->contains($agencyAccount)) {
$this->agencyAccounts[] = $agencyAccount;
$agencyAccount->setAgency($this);
}
return $this;
}
public function removeAgencyAccount(AgencyAccount $agencyAccount): self
{
if ($this->agencyAccounts->removeElement($agencyAccount)) {
// set the owning side to null (unless already changed)
if ($agencyAccount->getAgency() === $this) {
$agencyAccount->setAgency(null);
}
}
return $this;
}
/**
* @return Collection|AgencyExtension[]
*/
public function getAgencyExtensions(): Collection
{
return $this->agencyExtensions;
}
public function addAgencyExtension(AgencyExtension $agencyExtension): self
{
if (!$this->agencyExtensions->contains($agencyExtension)) {
$this->agencyExtensions[] = $agencyExtension;
$agencyExtension->setAgency($this);
}
return $this;
}
public function removeAgencyExtension(AgencyExtension $agencyExtension): self
{
if ($this->agencyExtensions->removeElement($agencyExtension)) {
// set the owning side to null (unless already changed)
if ($agencyExtension->getAgency() === $this) {
$agencyExtension->setAgency(null);
}
}
return $this;
}
#[ORM\PreUpdate]
public function onUpdate() {
$this->modifiedAt = new \DateTime();
}
/**
* @return Collection<int, Transfert>
*/
public function getTransferts(): Collection
{
return $this->transferts;
}
public function addTransfert(Transfert $transfert): static
{
if (!$this->transferts->contains($transfert)) {
$this->transferts->add($transfert);
$transfert->setStartingAgency($this);
}
return $this;
}
public function removeTransfert(Transfert $transfert): static
{
if ($this->transferts->removeElement($transfert)) {
// set the owning side to null (unless already changed)
if ($transfert->getStartingAgency() === $this) {
$transfert->setStartingAgency(null);
}
}
return $this;
}
}