<?php
namespace Evo\Infrastructure\MappingORM;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Enum\PersonTypeEnum;
use App\Utils\Nationality;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\PersistentCollection;
use Symfony\Component\Intl\Countries;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ApiResource(
* denormalizationContext={"groups"={"write_person"}},
* normalizationContext={"groups"={"read_person"}, "enable_max_depth"=true},
* itemOperations={
* "get"={"method"="GET", "path"="/people/{id}", "requirements"={"id"="\d+"}},
* "put"={"method"="PUT", "path"="/people/{id}", "requirements"={"id"="\d+"}},
* "get_documents"={"route_name"="get_documents_people", "method"="GET"},
* "delete"
* },
* collectionOperations={
* "get"={"method"="GET", "path"="/people"},
* "post"={"method"="POST", "path"="/people"}
* },
* )
* @ORM\Entity(repositoryClass="App\Repository\PersonRepository")
*/
class Person
{
/**
* @Groups({
* "read_search",
* "auditor",
* "associate",
* "read_accountant",
* "write_accountant",
* "legal_representative",
* "write_organization",
* "read_organization"
* })
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private ?int $id = null;
/**
* @Assert\Choice(callback={"App\Enum\GenderTypeEnum", "getChoices"})
* @Groups({"write_person", "read_person", "associate", "auditor", "legal_representative", "write_organization", "read_organization", "write_mandatary", "read_accountant", "write_accountant", "read_search"})
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $honorificPrefix = null;
/**
* @Groups({"write_person", "read_person",
* "associate",
* "auditor",
* "legal_representative",
* "write_organization", "read_organization",
* "write_mandatary",
* "read_accountant", "write_accountant",
* "read_export_organization",
* "read_search",
* "read_document",
* "admin:doc:list",
* "admin_orga_list",
* "pappers_activity"
* })
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $familyName = null;
/**
* @Groups({"write_person", "read_person",
* "associate",
* "auditor",
* "legal_representative",
* "write_organization", "read_organization",
* "write_mandatary",
* "read_accountant", "write_accountant",
* "read_export_organization",
* "read_search",
* "read_document",
* "admin:doc:list",
* "admin_orga_list",
* "pappers_activity"
* })
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $givenName = null;
/**
* @Groups({"write_person", "read_person",
* "associate",
* "auditor",
* "legal_representative",
* "write_organization",
* "write_mandatary",
* "read_accountant",
* "read_organization",
* "write_accountant",
* "read_search"
* })
* @ORM\OneToOne(targetEntity="Evo\Infrastructure\MappingORM\PostalAddress", cascade={"persist"})
*/
private ?PostalAddress $address = null;
/**
* @Groups({"write_person", "read_person",
* "associate",
* "auditor",
* "legal_representative",
* "write_organization", "read_organization",
* "write_mandatary",
* "read_accountant", "write_accountant",
* "pappers_activity"
* })
* @ORM\Column(type="date", nullable=true)
*/
private ?\DateTimeInterface $birthDate = null;
/**
* @Groups({"write_person", "read_person",
* "associate",
* "auditor",
* "legal_representative",
* "write_organization", "read_organization",
* "write_mandatary",
* "read_accountant", "write_accountant"})
* @MaxDepth(1)
* @ORM\OneToOne(targetEntity="Evo\Infrastructure\MappingORM\PostalAddress", cascade={"persist"})
*/
private ?PostalAddress $birthPlace = null;
/**
* @Groups({"write_person", "read_person",
* "associate",
* "auditor",
* "legal_representative",
* "write_organization", "read_organization",
* "write_mandatary",
* "read_accountant", "write_accountant"})
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $nationality = null;
/**
* @Assert\Choice(callback={"App\Enum\PersonTypeEnum", "getChoices"})
* @Groups({"write_person", "read_person",
* "associate",
* "auditor",
* "legal_representative",
* "write_organization", "read_organization",
* "write_mandatary",
* "read_accountant", "write_accountant",
* "read_export_organization",
* "pappers_activity"
* })
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $type = null;
/**
* @Groups({"write_person", "read_person",
* "associate",
* "auditor",
* "legal_representative",
* "write_organization", "read_organization",
* "write_mandatary",
* "read_accountant", "write_accountant"})
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $SIRET = null;
/**
* @Groups({"write_person", "read_person",
* "associate",
* "auditor",
* "legal_representative",
* "write_organization", "read_organization",
* "write_mandatary",
* "read_accountant", "write_accountant",
* "read_export_organization",
* "read_search",
* "admin:doc:list",
* "pappers_activity"
* })
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $legalName = null;
/**
* @Groups({"write_person", "read_person",
* "associate",
* "auditor",
* "legal_representative",
* "write_organization", "read_organization",
* "write_mandatary",
* "read_accountant", "write_accountant"})
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $registrationCity = null;
/**
* @Groups({"write_person", "read_person",
* "associate",
* "auditor",
* "legal_representative",
* "write_organization", "read_organization",
* "write_mandatary",
* "read_accountant", "write_accountant",
* "read_export_organization",
* "read_search",
* "pappers_activity"
* })
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $legalStatus = null;
/**
* @Groups({"write_person", "read_person",
* "associate",
* "auditor",
* "legal_representative",
* "write_organization", "read_organization",
* "write_mandatary",
* "read_accountant", "write_accountant"})
* @Assert\Choice(callback={"App\Enum\GenderTypeEnum", "getChoices"})
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $fatherHonorificPrefix = null;
/**
* @Groups({"write_person", "read_person",
* "associate",
* "auditor",
* "legal_representative",
* "write_organization", "read_organization",
* "write_mandatary",
* "read_accountant", "write_accountant"})
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $fatherFamilyName = null;
/**
* @Groups({"write_person", "read_person",
* "associate",
* "auditor",
* "legal_representative",
* "write_organization", "read_organization",
* "write_mandatary",
* "read_accountant", "write_accountant"})
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $fatherGivenName = null;
/**
* @Groups({"write_person", "read_person",
* "associate",
* "auditor",
* "legal_representative",
* "write_organization", "read_organization",
* "write_mandatary",
* "read_accountant", "write_accountant"})
* @Assert\Choice(callback={"App\Enum\GenderTypeEnum", "getChoices"})
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $motherHonorificPrefix = null;
/**
* @Groups({"write_person", "read_person",
* "associate",
* "auditor",
* "legal_representative",
* "write_organization", "read_organization",
* "write_mandatary",
* "read_accountant", "write_accountant"})
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $motherBirthName = null;
/**
* @Groups({"write_person", "read_person",
* "associate",
* "auditor",
* "legal_representative",
* "write_organization", "read_organization",
* "write_mandatary",
* "read_accountant", "write_accountant"})
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $motherGivenName = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $birthName = null;
/**
* @Groups({"write_person", "read_person","legal_representative", "read_organization", "write_organization"})
* @ORM\OneToMany(targetEntity="Evo\Infrastructure\MappingORM\Document", mappedBy="person", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
*/
private ?Collection $documents;
/**
* @Groups({"write_person", "read_person"})
* @ORM\OneToMany(targetEntity="Evo\Infrastructure\MappingORM\LegalRepresentative", mappedBy="person", cascade={"persist"})
*/
private ?Collection $legalRepresentatives = null;
/**
* @Groups({"write_person", "read_person","legal_representative", "read_organization", "write_organization", "associate"})
* @ORM\Column(type="boolean")
*/
private $isHosted = 0;
/**
* @Groups({"write_person", "read_person","legal_representative", "read_organization", "write_organization", "associate"})
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $securiteSociale = null;
/**
* @Groups({"write_person", "read_person","legal_representative", "read_organization", "write_organization", "associate"})
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $assuranceMaladie = null;
/**
* @Assert\Choice(callback={"App\Enum\TaxReportingEnum", "getChoices"})
* @Groups({"write_person", "read_person","legal_representative", "read_organization", "write_organization", "associate"})
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $declarationCotisation = null;
/**
* @Groups({"write_person", "read_person","legal_representative", "read_organization", "write_organization", "associate"})
* @ORM\Column(type="boolean", nullable=true)
*/
private $prelevementLiberatoireImpot;
public function __construct()
{
$this->documents = new ArrayCollection();
$this->legalRepresentatives = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getAddress(): ?PostalAddress
{
return $this->address;
}
public function setAddress(?PostalAddress $address): self
{
$this->address = $address;
return $this;
}
public function getBirthDate(): ?\DateTimeInterface
{
return $this->birthDate;
}
public function setBirthDate(?\DateTimeInterface $birthDate): self
{
$this->birthDate = $birthDate;
return $this;
}
public function getBirthPlace(): ?PostalAddress
{
return $this->birthPlace;
}
public function setBirthPlace(?PostalAddress $birthPlace): self
{
$this->birthPlace = $birthPlace;
return $this;
}
public function getNationality(): ?string
{
return $this->nationality;
}
public function setNationality(?string $nationality): self
{
$this->nationality = $nationality;
return $this;
}
public function getSIRET(): ?string
{
return $this->SIRET;
}
public function setSIRET(?string $SIRET): self
{
$this->SIRET = $SIRET;
return $this;
}
public function getRegistrationCity(): ?string
{
return $this->registrationCity;
}
public function setRegistrationCity(?string $registrationCity): self
{
$this->registrationCity = $registrationCity;
return $this;
}
public function getFatherHonorificPrefix(): ?string
{
return $this->fatherHonorificPrefix;
}
public function setFatherHonorificPrefix(?string $fatherHonorificPrefix): self
{
$this->fatherHonorificPrefix = $fatherHonorificPrefix;
return $this;
}
public function getFatherFamilyName(): ?string
{
return $this->fatherFamilyName;
}
public function setFatherFamilyName(?string $fatherFamilyName): self
{
$this->fatherFamilyName = $fatherFamilyName;
return $this;
}
public function getFatherGivenName(): ?string
{
return $this->fatherGivenName;
}
public function setFatherGivenName(?string $fatherGivenName): self
{
$this->fatherGivenName = $fatherGivenName;
return $this;
}
public function getMotherHonorificPrefix(): ?string
{
return $this->motherHonorificPrefix;
}
public function setMotherHonorificPrefix(?string $motherHonorificPrefix): self
{
$this->motherHonorificPrefix = $motherHonorificPrefix;
return $this;
}
public function getMotherBirthName(): ?string
{
return $this->motherBirthName;
}
public function setMotherBirthName(?string $motherBirthName): self
{
$this->motherBirthName = $motherBirthName;
return $this;
}
public function getMotherGivenName(): ?string
{
return $this->motherGivenName;
}
public function setMotherGivenName(?string $motherGivenName): self
{
$this->motherGivenName = $motherGivenName;
return $this;
}
public function __toString()
{
if (PersonTypeEnum::PHYSICAL == $this->getType()) {
return $this->getFamilyName().' '.$this->getGivenName();
}
$text = $this->getLegalName() ?? 'Inconnu';
if (!empty($this->getLegalStatus())) {
$text .= ' ('.$this->getLegalStatus().')';
}
return $text;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(?string $type): self
{
$this->type = $type;
return $this;
}
public function getHonorificPrefix(): ?string
{
return $this->honorificPrefix;
}
public function setHonorificPrefix(?string $honorificPrefix): self
{
$this->honorificPrefix = $honorificPrefix;
return $this;
}
public function getFamilyName(): ?string
{
return $this->familyName;
}
public function getLastname(): ?string
{
return $this->familyName;
}
public function setFamilyName(?string $familyName): self
{
$this->familyName = $familyName;
return $this;
}
public function getGivenName(): ?string
{
return $this->givenName;
}
public function getFirstname(): ?string
{
return $this->givenName;
}
public function setGivenName(?string $givenName): self
{
$this->givenName = $givenName;
return $this;
}
public function getLegalName(): ?string
{
return $this->legalName;
}
public function setLegalName(?string $legalName): self
{
$this->legalName = $legalName;
return $this;
}
public function getLegalStatus(): ?string
{
return $this->legalStatus;
}
public function setLegalStatus(?string $legalStatus): self
{
$this->legalStatus = $legalStatus;
return $this;
}
public function getBirthName(): ?string
{
return $this->birthName;
}
public function setBirthName(?string $birthName): self
{
$this->birthName = $birthName;
return $this;
}
/**
* @return Collection|Document[]
*/
public function getDocuments(): Collection
{
return $this->documents;
}
public function getExpiredDocuments(): Collection
{
$criteria = Criteria::create()->where(Criteria::expr()->lt('expirationDate', new \DateTime()));
if ($this->documents instanceof PersistentCollection) {
return $this->documents->matching($criteria);
}
return new ArrayCollection();
}
public function addDocument(Document $document): self
{
if (!$this->documents->contains($document)) {
$this->documents[] = $document;
$document->setPerson($this);
}
return $this;
}
public function removeDocument(Document $document): self
{
if ($this->documents->contains($document)) {
$this->documents->removeElement($document);
// set the owning side to null (unless already changed)
if ($document->getPerson() === $this) {
$document->setPerson(null);
}
}
return $this;
}
public function getIsHosted(): ?bool
{
return $this->isHosted;
}
public function setIsHosted(?bool $isHosted): self
{
$this->isHosted = $isHosted;
return $this;
}
/**
* @return Collection|LegalRepresentative[]
*/
public function getLegalRepresentatives(): Collection
{
if (!$this->legalRepresentatives) {
return new ArrayCollection();
}
return $this->legalRepresentatives;
}
public function getLegalRepresentative(): ?LegalRepresentative
{
if (count($this->legalRepresentatives) > 0) {
return $this->legalRepresentatives->first();
}
return null;
}
public function addLegalRepresentative(LegalRepresentative $legalRepresentative): self
{
if (!$this->legalRepresentatives->contains($legalRepresentative)) {
$this->legalRepresentatives[] = $legalRepresentative;
$legalRepresentative->setPerson($this);
}
return $this;
}
public function removeLegalRepresentative(LegalRepresentative $legalRepresentative): self
{
if ($this->legalRepresentatives->contains($legalRepresentative)) {
$this->legalRepresentatives->removeElement($legalRepresentative);
// set the owning side to null (unless already changed)
if ($legalRepresentative->getPerson() === $this) {
$legalRepresentative->setPerson(null);
}
}
return $this;
}
public function getSecuriteSociale(): ?string
{
return $this->securiteSociale;
}
public function setSecuriteSociale(?string $securiteSociale): self
{
$this->securiteSociale = $securiteSociale;
return $this;
}
public function getAssuranceMaladie(): ?string
{
return $this->assuranceMaladie;
}
public function setAssuranceMaladie(?string $assuranceMaladie): self
{
$this->assuranceMaladie = $assuranceMaladie;
return $this;
}
public function getDeclarationCotisation(): ?string
{
return $this->declarationCotisation;
}
public function getCountryTranslation()
{
if (!empty($this->getNationality()) && Countries::exists($this->getNationality())) {
return Countries::getName($this->getNationality());
}
return $this->getNationality();
}
public function getNationalityTranslation()
{
if (!empty($this->getNationality()) && Nationality::getName($this->getNationality())) {
return Nationality::getName($this->getNationality());
}
return $this->getNationality();
}
public function setDeclarationCotisation(?string $declarationCotisation): self
{
$this->declarationCotisation = $declarationCotisation;
return $this;
}
public function getPrelevementLiberatoireImpot(): ?bool
{
return $this->prelevementLiberatoireImpot;
}
public function setPrelevementLiberatoireImpot(?bool $prelevementLiberatoireImpot): self
{
$this->prelevementLiberatoireImpot = $prelevementLiberatoireImpot;
return $this;
}
public function getFullName(): string
{
if (PersonTypeEnum::PHYSICAL === $this->getType()) {
return $this->getFamilyName().' '.$this->getGivenName();
}
return $this->getLegalName();
}
public static function createFixture(array $data): Person
{
$self = new self();
$self->familyName = $data['familyName'];
$self->givenName = $data['givenName'];
$self->honorificPrefix = $data['honorificPrefix'] ?? 'MR';
$self->type = $data['type'] ?? PersonTypeEnum::PHYSICAL;
$self->isHosted = $data['isHosted'] ?? false;
return $self;
}
}