<?php
namespace App\Entity;
use App\Repository\CommercialRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use JetBrains\PhpStorm\Pure;
#[ORM\Entity(repositoryClass: CommercialRepository::class)]
class Commercial extends User
{
use IdentifiableTrait;
private static array $rolesList = [
'ROLE_VISIT_REPORT',
'ROLE_BOOKING_EVENT',
];
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTimeInterface $activityStartDate = null;
#[ORM\Column(length: 255)]
private ?string $firstname = null;
#[ORM\Column(length: 255)]
private ?string $lastname = null;
#[ORM\Column(length: 255)]
private ?string $address = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $address2 = null;
#[ORM\Column(length: 255)]
private ?string $postalCode = null;
#[ORM\Column(length: 255)]
private ?string $city = null;
#[ORM\Column(length: 255)]
private ?string $phone = null;
#[ORM\Column(length: 255)]
private ?string $code = null;
#[ORM\OneToMany(mappedBy: 'commercial', targetEntity: Prescriber::class)]
private Collection $prescribers;
#[ORM\OneToMany(mappedBy: 'commercial', targetEntity: Invoice::class)]
private Collection $invoices;
#[ORM\ManyToOne(inversedBy: 'commercials')]
#[ORM\JoinColumn(nullable: true)]
private ?Country $country = null;
#[ORM\ManyToMany(targetEntity: CommercialSaleZone::class, inversedBy: 'commercials')]
private Collection $saleZones;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $created_at = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $updated_at = null;
#[ORM\Column(nullable: true)]
private ?bool $archived = null;
#[ORM\OneToMany(mappedBy: 'visitedBy', targetEntity: VisitReport::class, orphanRemoval: true)]
private Collection $visitReports;
#[ORM\ManyToOne(inversedBy: 'commercials')]
private ?BillingCenter $mainBillingCenter = null;
#[ORM\ManyToMany(targetEntity: BookingEvent::class, mappedBy: 'referents')]
private Collection $referentsBookingEvents;
#[ORM\ManyToMany(targetEntity: BookingEvent::class, mappedBy: 'commercialSpeakers')]
private Collection $commercialSpeakersBookingEvents;
#[ORM\ManyToMany(targetEntity: BookingEvent::class, mappedBy: 'allowedCommercials')]
private Collection $bookingEventsAllowed;
#[ORM\Column(nullable: true)]
private ?bool $isDisplayedInForms = null;
public function __construct()
{
parent::__construct();
$this->invoices = new ArrayCollection();
$this->saleZones = new ArrayCollection();
$this->visitReports = new ArrayCollection();
$this->referentsBookingEvents = new ArrayCollection();
$this->commercialSpeakersBookingEvents = new ArrayCollection();
$this->bookingEventsAllowed = new ArrayCollection();
}
public function __toString(): string
{
return $this->getFullName();
}
public function getId(): ?int
{
return $this->id;
}
public function getActivityStartDate(): ?\DateTimeInterface
{
return $this->activityStartDate;
}
public function setActivityStartDate(\DateTimeInterface $activityStartDate): self
{
$this->activityStartDate = $activityStartDate;
return $this;
}
public function getFirstname(): ?string
{
return $this->firstname;
}
public function setFirstname(string $firstname): self
{
$this->firstname = $firstname;
return $this;
}
public function getLastname(): ?string
{
return $this->lastname;
}
public function setLastname(string $lastname): self
{
$this->lastname = $lastname;
return $this;
}
public function getFullName(): ?string
{
return $this->getLastname() . " " . $this->getFirstname();
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(string $address): self
{
$this->address = $address;
return $this;
}
public function getAddress2(): ?string
{
return $this->address2;
}
public function setAddress2(?string $address2): self
{
$this->address2 = $address2;
return $this;
}
public function getPostalCode(): ?string
{
return $this->postalCode;
}
public function setPostalCode(string $postalCode): self
{
$this->postalCode = $postalCode;
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(string $city): self
{
$this->city = $city;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
/**
* @return Collection<int, Prescriber>
*/
public function getPrescribers(): Collection
{
return $this->prescribers;
}
public function addPrescriber(Prescriber $prescriber): self
{
if (!$this->prescribers->contains($prescriber)) {
$this->prescribers->add($prescriber);
$prescriber->setCommercial($this);
}
return $this;
}
public function removePrescriber(Prescriber $prescriber): self
{
if ($this->prescribers->removeElement($prescriber)) {
// set the owning side to null (unless already changed)
if ($prescriber->getCommercial() === $this) {
$prescriber->setCommercial(null);
}
}
return $this;
}
/**
* @return Collection<int, Invoice>
*/
public function getInvoices(): Collection
{
return $this->invoices;
}
public function addInvoice(Invoice $invoice): self
{
if (!$this->invoices->contains($invoice)) {
$this->invoices->add($invoice);
$invoice->setCommercial($this);
}
return $this;
}
public function removeInvoice(Invoice $invoice): self
{
if ($this->invoices->removeElement($invoice)) {
// set the owning side to null (unless already changed)
if ($invoice->getCommercial() === $this) {
$invoice->setCommercial(null);
}
}
return $this;
}
public function getCountry(): ?Country
{
return $this->country;
}
public function setCountry(?Country $country): self
{
$this->country = $country;
return $this;
}
/**
* @return Collection<int, CommercialSaleZone>
*/
public function getSaleZones(): Collection
{
return $this->saleZones;
}
public function addSaleZone(CommercialSaleZone $saleZone): self
{
if (!$this->saleZones->contains($saleZone)) {
$this->saleZones->add($saleZone);
}
return $this;
}
public function removeSaleZone(CommercialSaleZone $saleZone): self
{
$this->saleZones->removeElement($saleZone);
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->created_at;
}
public function setCreatedAt(?\DateTimeImmutable $created_at): self
{
$this->created_at = $created_at;
return $this;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updated_at;
}
public function setUpdatedAt(?\DateTimeImmutable $updated_at): self
{
$this->updated_at = $updated_at;
return $this;
}
public function isArchived(): ?bool
{
return $this->archived;
}
public function setArchived(?bool $archived): static
{
$this->archived = $archived;
return $this;
}
/**
* @return Collection<int, VisitReport>
*/
public function getVisitReports(): Collection
{
return $this->visitReports;
}
public function addVisitReport(VisitReport $visitReport): static
{
if (!$this->visitReports->contains($visitReport)) {
$this->visitReports->add($visitReport);
$visitReport->setVisitedBy($this);
}
return $this;
}
public function removeVisitReport(VisitReport $visitReport): static
{
if ($this->visitReports->removeElement($visitReport)) {
// set the owning side to null (unless already changed)
if ($visitReport->getVisitedBy() === $this) {
$visitReport->setVisitedBy(null);
}
}
return $this;
}
public function getMainBillingCenter(): ?BillingCenter
{
return $this->mainBillingCenter;
}
public function setMainBillingCenter(?BillingCenter $mainBillingCenter): static
{
$this->mainBillingCenter = $mainBillingCenter;
return $this;
}
public function setVisitReportRights(bool $visitReportRights): self
{
return $this->setRoleRights('ROLE_VISIT_REPORT', $visitReportRights);
}
public function hasVisitReportRights(): bool
{
return $this->hasRole('ROLE_VISIT_REPORT');
}
public function setBookingEventRights(bool $BookingEventRights): self
{
return $this->setRoleRights('ROLE_BOOKING_EVENT', $BookingEventRights);
}
public function hasBookingEventRights(): bool
{
return $this->hasRole('ROLE_BOOKING_EVENT');
}
private function setRoleRights(string $role, bool $hasRights): self
{
if ($hasRights) {
if (!in_array($role, $this->roles, true)) {
$this->roles[] = $role;
}
} else {
$this->roles = array_diff($this->roles, [$role]);
}
return $this;
}
public function getRoles(): array
{
$roles = parent::getRoles();
foreach (self::$rolesList as $role) {
if ($this->hasRole($role)) {
$roles[] = $role;
}
}
return array_unique($roles);
}
/**
* @return Collection<int, BookingEvent>
*/
public function getPrescriberSpeakersBookingEvents(): Collection
{
return $this->referentsBookingEvents;
}
public function addBookingEvent(BookingEvent $referentsBookingEvents): static
{
if (!$this->referentsBookingEvents->contains($referentsBookingEvents)) {
$this->referentsBookingEvents->add($referentsBookingEvents);
$referentsBookingEvents->addCommercial($this); // Assurez-vous que cette opération ne crée pas une boucle infinie
}
return $this;
}
public function removeBookingEvent(BookingEvent $referentsBookingEvents): static
{
if ($this->referentsBookingEvents->removeElement($referentsBookingEvents)) {
$referentsBookingEvents->removeCommercial($this); // Assurez-vous que cette opération ne crée pas une boucle infinie
}
return $this;
}
/**
* @return Collection<int, BookingEvent>
*/
public function getCommercialSpeakersBookingEvents(): Collection
{
return $this->commercialSpeakersBookingEvents;
}
public function addCommercialSpeakersBookingEvent(BookingEvent $commercialSpeakersBookingEvent): static
{
if (!$this->commercialSpeakersBookingEvents->contains($commercialSpeakersBookingEvent)) {
$this->commercialSpeakersBookingEvents->add($commercialSpeakersBookingEvent);
$commercialSpeakersBookingEvent->addCommercialSpeaker($this);
}
return $this;
}
public function removeCommercialSpeakersBookingEvent(BookingEvent $commercialSpeakersBookingEvent): static
{
if ($this->commercialSpeakersBookingEvents->removeElement($commercialSpeakersBookingEvent)) {
$commercialSpeakersBookingEvent->removeCommercialSpeaker($this);
}
return $this;
}
/**
* @return Collection<int, BookingEvent>
*/
public function getBookingEventsAllowed(): Collection
{
return $this->bookingEventsAllowed;
}
public function addBookingEventsAllowed(BookingEvent $bookingEventsAllowed): static
{
if (!$this->bookingEventsAllowed->contains($bookingEventsAllowed)) {
$this->bookingEventsAllowed->add($bookingEventsAllowed);
$bookingEventsAllowed->addAllowedCommercial($this);
}
return $this;
}
public function removeBookingEventsAllowed(BookingEvent $bookingEventsAllowed): static
{
if ($this->bookingEventsAllowed->removeElement($bookingEventsAllowed)) {
$bookingEventsAllowed->removeAllowedCommercial($this);
}
return $this;
}
public function isIsDisplayedInForms(): ?bool
{
return $this->isDisplayedInForms;
}
public function setIsDisplayedInForms(?bool $isDisplayedInForms): static
{
$this->isDisplayedInForms = $isDisplayedInForms;
return $this;
}
}