src/Evo/Infrastructure/MappingORM/Person.php line 35

Open in your IDE?
  1. <?php
  2. namespace Evo\Infrastructure\MappingORM;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Enum\PersonTypeEnum;
  5. use App\Utils\Nationality;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\Common\Collections\Criteria;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Doctrine\ORM\PersistentCollection;
  11. use Symfony\Component\Intl\Countries;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. use Symfony\Component\Serializer\Annotation\MaxDepth;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. /**
  16.  * @ApiResource(
  17.  *     denormalizationContext={"groups"={"write_person"}},
  18.  *     normalizationContext={"groups"={"read_person"}, "enable_max_depth"=true},
  19.  *     itemOperations={
  20.  *          "get"={"method"="GET", "path"="/people/{id}", "requirements"={"id"="\d+"}},
  21.  *          "put"={"method"="PUT", "path"="/people/{id}", "requirements"={"id"="\d+"}},
  22.  *          "get_documents"={"route_name"="get_documents_people", "method"="GET"},
  23.  *          "delete"
  24.  *     },
  25.  *     collectionOperations={
  26.  *          "get"={"method"="GET", "path"="/people"},
  27.  *          "post"={"method"="POST", "path"="/people"}
  28.  *     },
  29.  *     )
  30.  * @ORM\Entity(repositoryClass="App\Repository\PersonRepository")
  31.  */
  32. class Person
  33. {
  34.     /**
  35.      * @Groups({
  36.      *     "read_search",
  37.      *     "auditor",
  38.      *     "associate",
  39.      *     "read_accountant",
  40.      *     "write_accountant",
  41.      *     "legal_representative",
  42.      *     "write_organization",
  43.      *     "read_organization"
  44.      * })
  45.      * @ORM\Id()
  46.      * @ORM\GeneratedValue()
  47.      * @ORM\Column(type="integer")
  48.      */
  49.     private ?int $id null;
  50.     /**
  51.      * @Assert\Choice(callback={"App\Enum\GenderTypeEnum", "getChoices"})
  52.      * @Groups({"write_person", "read_person", "associate", "auditor", "legal_representative", "write_organization", "read_organization", "write_mandatary", "read_accountant", "write_accountant", "read_search"})
  53.      * @ORM\Column(type="string", length=255, nullable=true)
  54.      */
  55.     private ?string $honorificPrefix null;
  56.     /**
  57.      * @Groups({"write_person", "read_person",
  58.      *     "associate",
  59.      *     "auditor",
  60.      *     "legal_representative",
  61.      *     "write_organization", "read_organization",
  62.      *     "write_mandatary",
  63.      *     "read_accountant", "write_accountant",
  64.      *     "read_export_organization",
  65.      *     "read_search",
  66.      *     "read_document",
  67.      *     "admin:doc:list",
  68.      *     "admin_orga_list",
  69.      *     "pappers_activity"
  70.      * })
  71.      * @ORM\Column(type="string", length=255, nullable=true)
  72.      */
  73.     private ?string $familyName null;
  74.     /**
  75.      * @Groups({"write_person", "read_person",
  76.      *     "associate",
  77.      *     "auditor",
  78.      *     "legal_representative",
  79.      *     "write_organization", "read_organization",
  80.      *     "write_mandatary",
  81.      *     "read_accountant", "write_accountant",
  82.      *     "read_export_organization",
  83.      *     "read_search",
  84.      *     "read_document",
  85.      *     "admin:doc:list",
  86.      *     "admin_orga_list",
  87.      *     "pappers_activity"
  88.      * })
  89.      * @ORM\Column(type="string", length=255, nullable=true)
  90.      */
  91.     private ?string $givenName null;
  92.     /**
  93.      * @Groups({"write_person", "read_person",
  94.      *     "associate",
  95.      *     "auditor",
  96.      *     "legal_representative",
  97.      *     "write_organization",
  98.      *     "write_mandatary",
  99.      *     "read_accountant",
  100.      *     "read_organization",
  101.      *     "write_accountant",
  102.      *     "read_search"
  103.      * })
  104.      * @ORM\OneToOne(targetEntity="Evo\Infrastructure\MappingORM\PostalAddress", cascade={"persist"})
  105.      */
  106.     private ?PostalAddress $address null;
  107.     /**
  108.      * @Groups({"write_person", "read_person",
  109.      *     "associate",
  110.      *     "auditor",
  111.      *     "legal_representative",
  112.      *     "write_organization", "read_organization",
  113.      *     "write_mandatary",
  114.      *     "read_accountant", "write_accountant",
  115.      *     "pappers_activity"
  116.      * })
  117.      * @ORM\Column(type="date", nullable=true)
  118.      */
  119.     private ?\DateTimeInterface $birthDate null;
  120.     /**
  121.      * @Groups({"write_person", "read_person",
  122.      *     "associate",
  123.      *     "auditor",
  124.      *     "legal_representative",
  125.      *     "write_organization", "read_organization",
  126.      *     "write_mandatary",
  127.      *     "read_accountant", "write_accountant"})
  128.      * @MaxDepth(1)
  129.      * @ORM\OneToOne(targetEntity="Evo\Infrastructure\MappingORM\PostalAddress", cascade={"persist"})
  130.      */
  131.     private ?PostalAddress $birthPlace null;
  132.     /**
  133.      * @Groups({"write_person", "read_person",
  134.      *     "associate",
  135.      *     "auditor",
  136.      *     "legal_representative",
  137.      *     "write_organization", "read_organization",
  138.      *     "write_mandatary",
  139.      *     "read_accountant", "write_accountant"})
  140.      * @ORM\Column(type="string", length=255, nullable=true)
  141.      */
  142.     private ?string $nationality null;
  143.     /**
  144.      * @Assert\Choice(callback={"App\Enum\PersonTypeEnum", "getChoices"})
  145.      * @Groups({"write_person", "read_person",
  146.      *     "associate",
  147.      *     "auditor",
  148.      *     "legal_representative",
  149.      *     "write_organization", "read_organization",
  150.      *     "write_mandatary",
  151.      *     "read_accountant", "write_accountant",
  152.      *     "read_export_organization",
  153.      *     "pappers_activity"
  154.      * })
  155.      * @ORM\Column(type="string", length=255, nullable=true)
  156.      */
  157.     private ?string $type null;
  158.     /**
  159.      * @Groups({"write_person", "read_person",
  160.      *     "associate",
  161.      *     "auditor",
  162.      *     "legal_representative",
  163.      *     "write_organization", "read_organization",
  164.      *     "write_mandatary",
  165.      *     "read_accountant", "write_accountant"})
  166.      * @ORM\Column(type="string", length=255, nullable=true)
  167.      */
  168.     private ?string $SIRET null;
  169.     /**
  170.      * @Groups({"write_person", "read_person",
  171.      *     "associate",
  172.      *     "auditor",
  173.      *     "legal_representative",
  174.      *     "write_organization", "read_organization",
  175.      *     "write_mandatary",
  176.      *     "read_accountant", "write_accountant",
  177.      *     "read_export_organization",
  178.      *     "read_search",
  179.      *     "admin:doc:list",
  180.      *     "pappers_activity"
  181.      * })
  182.      * @ORM\Column(type="string", length=255, nullable=true)
  183.      */
  184.     private ?string $legalName null;
  185.     /**
  186.      * @Groups({"write_person", "read_person",
  187.      *     "associate",
  188.      *     "auditor",
  189.      *     "legal_representative",
  190.      *     "write_organization", "read_organization",
  191.      *     "write_mandatary",
  192.      *     "read_accountant", "write_accountant"})
  193.      * @ORM\Column(type="string", length=255, nullable=true)
  194.      */
  195.     private ?string $registrationCity null;
  196.     /**
  197.      * @Groups({"write_person", "read_person",
  198.      *     "associate",
  199.      *     "auditor",
  200.      *     "legal_representative",
  201.      *     "write_organization", "read_organization",
  202.      *     "write_mandatary",
  203.      *     "read_accountant", "write_accountant",
  204.      *     "read_export_organization",
  205.      *     "read_search",
  206.      *     "pappers_activity"
  207.      * })
  208.      * @ORM\Column(type="string", length=255, nullable=true)
  209.      */
  210.     private ?string $legalStatus null;
  211.     /**
  212.      * @Groups({"write_person", "read_person",
  213.      *     "associate",
  214.      *     "auditor",
  215.      *     "legal_representative",
  216.      *     "write_organization", "read_organization",
  217.      *     "write_mandatary",
  218.      *     "read_accountant", "write_accountant"})
  219.      * @Assert\Choice(callback={"App\Enum\GenderTypeEnum", "getChoices"})
  220.      * @ORM\Column(type="string", length=255, nullable=true)
  221.      */
  222.     private ?string $fatherHonorificPrefix null;
  223.     /**
  224.      * @Groups({"write_person", "read_person",
  225.      *     "associate",
  226.      *     "auditor",
  227.      *     "legal_representative",
  228.      *     "write_organization", "read_organization",
  229.      *     "write_mandatary",
  230.      *     "read_accountant", "write_accountant"})
  231.      * @ORM\Column(type="string", length=255, nullable=true)
  232.      */
  233.     private ?string $fatherFamilyName null;
  234.     /**
  235.      * @Groups({"write_person", "read_person",
  236.      *     "associate",
  237.      *     "auditor",
  238.      *     "legal_representative",
  239.      *     "write_organization", "read_organization",
  240.      *     "write_mandatary",
  241.      *     "read_accountant", "write_accountant"})
  242.      * @ORM\Column(type="string", length=255, nullable=true)
  243.      */
  244.     private ?string $fatherGivenName null;
  245.     /**
  246.      * @Groups({"write_person", "read_person",
  247.      *     "associate",
  248.      *     "auditor",
  249.      *     "legal_representative",
  250.      *     "write_organization", "read_organization",
  251.      *     "write_mandatary",
  252.      *     "read_accountant", "write_accountant"})
  253.      * @Assert\Choice(callback={"App\Enum\GenderTypeEnum", "getChoices"})
  254.      * @ORM\Column(type="string", length=255, nullable=true)
  255.      */
  256.     private ?string $motherHonorificPrefix null;
  257.     /**
  258.      * @Groups({"write_person", "read_person",
  259.      *     "associate",
  260.      *     "auditor",
  261.      *     "legal_representative",
  262.      *     "write_organization", "read_organization",
  263.      *     "write_mandatary",
  264.      *     "read_accountant", "write_accountant"})
  265.      * @ORM\Column(type="string", length=255, nullable=true)
  266.      */
  267.     private ?string $motherBirthName null;
  268.     /**
  269.      * @Groups({"write_person", "read_person",
  270.      *     "associate",
  271.      *     "auditor",
  272.      *     "legal_representative",
  273.      *     "write_organization", "read_organization",
  274.      *     "write_mandatary",
  275.      *     "read_accountant", "write_accountant"})
  276.      * @ORM\Column(type="string", length=255, nullable=true)
  277.      */
  278.     private ?string $motherGivenName null;
  279.     /**
  280.      * @ORM\Column(type="string", length=255, nullable=true)
  281.      */
  282.     private ?string $birthName null;
  283.     /**
  284.      * @Groups({"write_person", "read_person","legal_representative", "read_organization", "write_organization"})
  285.      * @ORM\OneToMany(targetEntity="Evo\Infrastructure\MappingORM\Document", mappedBy="person", cascade={"persist"})
  286.      * @ORM\JoinColumn(nullable=false)
  287.      */
  288.     private ?Collection $documents;
  289.     /**
  290.      * @Groups({"write_person", "read_person"})
  291.      * @ORM\OneToMany(targetEntity="Evo\Infrastructure\MappingORM\LegalRepresentative", mappedBy="person", cascade={"persist"})
  292.      */
  293.     private ?Collection $legalRepresentatives null;
  294.     /**
  295.      * @Groups({"write_person", "read_person","legal_representative", "read_organization", "write_organization", "associate"})
  296.      * @ORM\Column(type="boolean")
  297.      */
  298.     private $isHosted 0;
  299.     /**
  300.      * @Groups({"write_person", "read_person","legal_representative", "read_organization", "write_organization", "associate"})
  301.      * @ORM\Column(type="string", length=255, nullable=true)
  302.      */
  303.     private ?string $securiteSociale null;
  304.     /**
  305.      * @Groups({"write_person", "read_person","legal_representative", "read_organization", "write_organization", "associate"})
  306.      * @ORM\Column(type="string", length=255, nullable=true)
  307.      */
  308.     private ?string $assuranceMaladie null;
  309.     /**
  310.      * @Assert\Choice(callback={"App\Enum\TaxReportingEnum", "getChoices"})
  311.      * @Groups({"write_person", "read_person","legal_representative", "read_organization", "write_organization", "associate"})
  312.      * @ORM\Column(type="string", length=255, nullable=true)
  313.      */
  314.     private ?string $declarationCotisation null;
  315.     /**
  316.      * @Groups({"write_person", "read_person","legal_representative", "read_organization", "write_organization", "associate"})
  317.      * @ORM\Column(type="boolean", nullable=true)
  318.      */
  319.     private $prelevementLiberatoireImpot;
  320.     public function __construct()
  321.     {
  322.         $this->documents = new ArrayCollection();
  323.         $this->legalRepresentatives = new ArrayCollection();
  324.     }
  325.     public function getId(): ?int
  326.     {
  327.         return $this->id;
  328.     }
  329.     public function getAddress(): ?PostalAddress
  330.     {
  331.         return $this->address;
  332.     }
  333.     public function setAddress(?PostalAddress $address): self
  334.     {
  335.         $this->address $address;
  336.         return $this;
  337.     }
  338.     public function getBirthDate(): ?\DateTimeInterface
  339.     {
  340.         return $this->birthDate;
  341.     }
  342.     public function setBirthDate(?\DateTimeInterface $birthDate): self
  343.     {
  344.         $this->birthDate $birthDate;
  345.         return $this;
  346.     }
  347.     public function getBirthPlace(): ?PostalAddress
  348.     {
  349.         return $this->birthPlace;
  350.     }
  351.     public function setBirthPlace(?PostalAddress $birthPlace): self
  352.     {
  353.         $this->birthPlace $birthPlace;
  354.         return $this;
  355.     }
  356.     public function getNationality(): ?string
  357.     {
  358.         return $this->nationality;
  359.     }
  360.     public function setNationality(?string $nationality): self
  361.     {
  362.         $this->nationality $nationality;
  363.         return $this;
  364.     }
  365.     public function getSIRET(): ?string
  366.     {
  367.         return $this->SIRET;
  368.     }
  369.     public function setSIRET(?string $SIRET): self
  370.     {
  371.         $this->SIRET $SIRET;
  372.         return $this;
  373.     }
  374.     public function getRegistrationCity(): ?string
  375.     {
  376.         return $this->registrationCity;
  377.     }
  378.     public function setRegistrationCity(?string $registrationCity): self
  379.     {
  380.         $this->registrationCity $registrationCity;
  381.         return $this;
  382.     }
  383.     public function getFatherHonorificPrefix(): ?string
  384.     {
  385.         return $this->fatherHonorificPrefix;
  386.     }
  387.     public function setFatherHonorificPrefix(?string $fatherHonorificPrefix): self
  388.     {
  389.         $this->fatherHonorificPrefix $fatherHonorificPrefix;
  390.         return $this;
  391.     }
  392.     public function getFatherFamilyName(): ?string
  393.     {
  394.         return $this->fatherFamilyName;
  395.     }
  396.     public function setFatherFamilyName(?string $fatherFamilyName): self
  397.     {
  398.         $this->fatherFamilyName $fatherFamilyName;
  399.         return $this;
  400.     }
  401.     public function getFatherGivenName(): ?string
  402.     {
  403.         return $this->fatherGivenName;
  404.     }
  405.     public function setFatherGivenName(?string $fatherGivenName): self
  406.     {
  407.         $this->fatherGivenName $fatherGivenName;
  408.         return $this;
  409.     }
  410.     public function getMotherHonorificPrefix(): ?string
  411.     {
  412.         return $this->motherHonorificPrefix;
  413.     }
  414.     public function setMotherHonorificPrefix(?string $motherHonorificPrefix): self
  415.     {
  416.         $this->motherHonorificPrefix $motherHonorificPrefix;
  417.         return $this;
  418.     }
  419.     public function getMotherBirthName(): ?string
  420.     {
  421.         return $this->motherBirthName;
  422.     }
  423.     public function setMotherBirthName(?string $motherBirthName): self
  424.     {
  425.         $this->motherBirthName $motherBirthName;
  426.         return $this;
  427.     }
  428.     public function getMotherGivenName(): ?string
  429.     {
  430.         return $this->motherGivenName;
  431.     }
  432.     public function setMotherGivenName(?string $motherGivenName): self
  433.     {
  434.         $this->motherGivenName $motherGivenName;
  435.         return $this;
  436.     }
  437.     public function __toString()
  438.     {
  439.         if (PersonTypeEnum::PHYSICAL == $this->getType()) {
  440.             return $this->getFamilyName().' '.$this->getGivenName();
  441.         }
  442.         $text $this->getLegalName() ?? 'Inconnu';
  443.         if (!empty($this->getLegalStatus())) {
  444.             $text .= ' ('.$this->getLegalStatus().')';
  445.         }
  446.         return $text;
  447.     }
  448.     public function getType(): ?string
  449.     {
  450.         return $this->type;
  451.     }
  452.     public function setType(?string $type): self
  453.     {
  454.         $this->type $type;
  455.         return $this;
  456.     }
  457.     public function getHonorificPrefix(): ?string
  458.     {
  459.         return $this->honorificPrefix;
  460.     }
  461.     public function setHonorificPrefix(?string $honorificPrefix): self
  462.     {
  463.         $this->honorificPrefix $honorificPrefix;
  464.         return $this;
  465.     }
  466.     public function getFamilyName(): ?string
  467.     {
  468.         return $this->familyName;
  469.     }
  470.     public function getLastname(): ?string
  471.     {
  472.         return $this->familyName;
  473.     }
  474.     public function setFamilyName(?string $familyName): self
  475.     {
  476.         $this->familyName $familyName;
  477.         return $this;
  478.     }
  479.     public function getGivenName(): ?string
  480.     {
  481.         return $this->givenName;
  482.     }
  483.     public function getFirstname(): ?string
  484.     {
  485.         return $this->givenName;
  486.     }
  487.     public function setGivenName(?string $givenName): self
  488.     {
  489.         $this->givenName $givenName;
  490.         return $this;
  491.     }
  492.     public function getLegalName(): ?string
  493.     {
  494.         return $this->legalName;
  495.     }
  496.     public function setLegalName(?string $legalName): self
  497.     {
  498.         $this->legalName $legalName;
  499.         return $this;
  500.     }
  501.     public function getLegalStatus(): ?string
  502.     {
  503.         return $this->legalStatus;
  504.     }
  505.     public function setLegalStatus(?string $legalStatus): self
  506.     {
  507.         $this->legalStatus $legalStatus;
  508.         return $this;
  509.     }
  510.     public function getBirthName(): ?string
  511.     {
  512.         return $this->birthName;
  513.     }
  514.     public function setBirthName(?string $birthName): self
  515.     {
  516.         $this->birthName $birthName;
  517.         return $this;
  518.     }
  519.     /**
  520.      * @return Collection|Document[]
  521.      */
  522.     public function getDocuments(): Collection
  523.     {
  524.         return $this->documents;
  525.     }
  526.     public function getExpiredDocuments(): Collection
  527.     {
  528.         $criteria Criteria::create()->where(Criteria::expr()->lt('expirationDate', new \DateTime()));
  529.         if ($this->documents instanceof PersistentCollection) {
  530.             return $this->documents->matching($criteria);
  531.         }
  532.         return new ArrayCollection();
  533.     }
  534.     public function addDocument(Document $document): self
  535.     {
  536.         if (!$this->documents->contains($document)) {
  537.             $this->documents[] = $document;
  538.             $document->setPerson($this);
  539.         }
  540.         return $this;
  541.     }
  542.     public function removeDocument(Document $document): self
  543.     {
  544.         if ($this->documents->contains($document)) {
  545.             $this->documents->removeElement($document);
  546.             // set the owning side to null (unless already changed)
  547.             if ($document->getPerson() === $this) {
  548.                 $document->setPerson(null);
  549.             }
  550.         }
  551.         return $this;
  552.     }
  553.     public function getIsHosted(): ?bool
  554.     {
  555.         return $this->isHosted;
  556.     }
  557.     public function setIsHosted(?bool $isHosted): self
  558.     {
  559.         $this->isHosted $isHosted;
  560.         return $this;
  561.     }
  562.     /**
  563.      * @return Collection|LegalRepresentative[]
  564.      */
  565.     public function getLegalRepresentatives(): Collection
  566.     {
  567.         if (!$this->legalRepresentatives) {
  568.             return new ArrayCollection();
  569.         }
  570.         return $this->legalRepresentatives;
  571.     }
  572.     public function getLegalRepresentative(): ?LegalRepresentative
  573.     {
  574.         if (count($this->legalRepresentatives) > 0) {
  575.             return $this->legalRepresentatives->first();
  576.         }
  577.         return null;
  578.     }
  579.     public function addLegalRepresentative(LegalRepresentative $legalRepresentative): self
  580.     {
  581.         if (!$this->legalRepresentatives->contains($legalRepresentative)) {
  582.             $this->legalRepresentatives[] = $legalRepresentative;
  583.             $legalRepresentative->setPerson($this);
  584.         }
  585.         return $this;
  586.     }
  587.     public function removeLegalRepresentative(LegalRepresentative $legalRepresentative): self
  588.     {
  589.         if ($this->legalRepresentatives->contains($legalRepresentative)) {
  590.             $this->legalRepresentatives->removeElement($legalRepresentative);
  591.             // set the owning side to null (unless already changed)
  592.             if ($legalRepresentative->getPerson() === $this) {
  593.                 $legalRepresentative->setPerson(null);
  594.             }
  595.         }
  596.         return $this;
  597.     }
  598.     public function getSecuriteSociale(): ?string
  599.     {
  600.         return $this->securiteSociale;
  601.     }
  602.     public function setSecuriteSociale(?string $securiteSociale): self
  603.     {
  604.         $this->securiteSociale $securiteSociale;
  605.         return $this;
  606.     }
  607.     public function getAssuranceMaladie(): ?string
  608.     {
  609.         return $this->assuranceMaladie;
  610.     }
  611.     public function setAssuranceMaladie(?string $assuranceMaladie): self
  612.     {
  613.         $this->assuranceMaladie $assuranceMaladie;
  614.         return $this;
  615.     }
  616.     public function getDeclarationCotisation(): ?string
  617.     {
  618.         return $this->declarationCotisation;
  619.     }
  620.     public function getCountryTranslation()
  621.     {
  622.         if (!empty($this->getNationality()) && Countries::exists($this->getNationality())) {
  623.             return Countries::getName($this->getNationality());
  624.         }
  625.         return $this->getNationality();
  626.     }
  627.     public function getNationalityTranslation()
  628.     {
  629.         if (!empty($this->getNationality()) && Nationality::getName($this->getNationality())) {
  630.             return Nationality::getName($this->getNationality());
  631.         }
  632.         return $this->getNationality();
  633.     }
  634.     public function setDeclarationCotisation(?string $declarationCotisation): self
  635.     {
  636.         $this->declarationCotisation $declarationCotisation;
  637.         return $this;
  638.     }
  639.     public function getPrelevementLiberatoireImpot(): ?bool
  640.     {
  641.         return $this->prelevementLiberatoireImpot;
  642.     }
  643.     public function setPrelevementLiberatoireImpot(?bool $prelevementLiberatoireImpot): self
  644.     {
  645.         $this->prelevementLiberatoireImpot $prelevementLiberatoireImpot;
  646.         return $this;
  647.     }
  648.     public function getFullName(): string
  649.     {
  650.         if (PersonTypeEnum::PHYSICAL === $this->getType()) {
  651.             return $this->getFamilyName().' '.$this->getGivenName();
  652.         }
  653.         return $this->getLegalName();
  654.     }
  655.     public static function createFixture(array $data): Person
  656.     {
  657.         $self = new self();
  658.         $self->familyName $data['familyName'];
  659.         $self->givenName $data['givenName'];
  660.         $self->honorificPrefix $data['honorificPrefix'] ?? 'MR';
  661.         $self->type $data['type'] ?? PersonTypeEnum::PHYSICAL;
  662.         $self->isHosted $data['isHosted'] ?? false;
  663.         return $self;
  664.     }
  665. }