src/Containers/CrmSection/ClientContainer/Entities/ClientEntity.php line 115

Open in your IDE?
  1. <?php
  2. namespace App\Containers\CrmSection\ClientContainer\Entities;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Delete;
  5. use ApiPlatform\Metadata\Get;
  6. use ApiPlatform\Metadata\GetCollection;
  7. use ApiPlatform\Metadata\Patch;
  8. use ApiPlatform\Metadata\Put;
  9. use ApiPlatform\Metadata\Post;
  10. use ApiPlatform\Metadata\ApiFilter;
  11. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  12. use ApiPlatform\Doctrine\Orm\Filter\NumericFilter;
  13. use ApiPlatform\Doctrine\Orm\Filter\RangeFilter;
  14. use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
  15. use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
  16. use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  17. use Doctrine\ORM\Mapping as ORM;
  18. use Doctrine\DBAL\Types\Types;
  19. use Gedmo\Mapping\Annotation as Gedmo;
  20. use Symfony\Component\Serializer\Annotation\Groups;
  21. use Symfony\Component\Serializer\Annotation\MaxDepth;
  22. use Symfony\Component\Serializer\Annotation\Context;
  23. use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
  24. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  25. use App\Ship\Utils\FormattingUtil;
  26. use App\Containers\CrmSection\ClientContainer\Data\Repositories\ClientRepository;
  27. use App\Containers\SettingSection\ListContainer\Entities\StatusEntity;
  28. use App\Containers\SettingSection\ListContainer\Entities\VerificationTypeEntity;
  29. use App\Containers\SettingSection\ListContainer\Entities\GenderEntity;
  30. use App\Containers\SettingSection\ListContainer\Entities\DocumentTypeEntity;
  31. use App\Containers\SettingSection\ListContainer\Entities\MobileAppVersionEntity;
  32. use App\Containers\SettingSection\ListContainer\Entities\DepartmentEntity;
  33. use App\Ship\Entities\UserEntity;
  34. use App\Containers\CrmSection\IndexContainer\Entities\TranslationEntity;
  35. use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
  36. use App\Ship\ApiPlatform\Filter\FilterLogic;
  37. /** 
  38.  * Клиент
  39. */
  40. #[ApiResource(
  41.     routePrefix'/crm',
  42.     normalizationContext: [
  43.         'groups' => 'read',
  44.         'enable_max_depth' => true
  45.     ],
  46.     operations: [
  47.         new Get(
  48.             uriTemplate'/clients/{id}'requirements: ['id' => '\d+'],
  49.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_INSTALLER') or is_granted('ROLE_READONLY') or is_granted('ROLE_DEPARTMENT_EMPLOYEE')"
  50.         ),
  51.         new Patch(
  52.             uriTemplate'/clients/{id}'requirements: ['id' => '\d+'],
  53.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  54.         ),
  55.         // new Put(
  56.         //     uriTemplate: '/clients/{id}', requirements: ['id' => '\d+'],
  57.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  58.         // ),
  59.         new Delete(
  60.             uriTemplate'/clients/{id}'requirements: ['id' => '\d+'],
  61.             security"is_granted('ROLE_ADMIN')"
  62.         ),
  63.         // new Post(
  64.         //     uriTemplate: '/clients',
  65.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  66.         // ),
  67.         new GetCollection(
  68.             uriTemplate'/clients',
  69.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_INSTALLER') or is_granted('ROLE_READONLY') or is_granted('ROLE_DEPARTMENT_EMPLOYEE')"
  70.         ),
  71.     ],
  72.     shortName'CRM_Clients'
  73. )]
  74. #[ApiFilter(SearchFilter::class, properties: [
  75.     'id' => 'exact'
  76.     'name' => 'partial'
  77.     'lastName' => 'partial'
  78.     'patronymic' => 'partial'
  79.     'externalCode' => 'partial'
  80.     'status' => 'exact',
  81.     'verificationType' => 'exact',
  82.     'gender' => 'exact',
  83.     'department' => 'exact',
  84.     'registrationLocality' => 'partial'
  85.     'registrationStreet' => 'partial'
  86.     'registrationHouseNumber' => 'exact'
  87.     'registrationRoomNumber' => 'exact'
  88.     'phone' => 'exact',
  89.     'additionalPhones' => 'partial',
  90.     'email' => 'exact'
  91.     'inn' => 'exact'
  92.     'documentId' => 'exact'
  93.     'documentIssuingAuthority' => 'exact'
  94.     'gender.name' => 'exact'
  95.     'gender.externalCode' => 'exact'
  96.     'documentType.name' => 'exact'
  97.     'documentType.externalCode' => 'exact'
  98. ])]
  99. #[ApiFilter(NumericFilter::class, properties: ['id'])]
  100. #[ApiFilter(RangeFilter::class, properties: ['id'])]
  101. #[ApiFilter(BooleanFilter::class, properties: ['isActive''isTest''isIgnoreFinancialMonitoring''isLimitConfirmed'])]
  102. #[ApiFilter(DateFilter::class, properties: ['dateBirth''documentIssueDate''dateLimitConfirmed'])]
  103. #[ApiFilter(OrderFilter::class)]
  104. #[ApiFilter(FilterLogic::class)]
  105. #[ApiFilter(filterClassSimpleSearchFilter::class, properties: [
  106.     'name''lastName''patronymic''externalCode',
  107.     'registrationLocality''registrationStreet',
  108.     'phone''email''inn'
  109. ])]
  110. #[ORM\Entity(repositoryClassClientRepository::class)]
  111. #[ORM\Table(name'`crm_clients`')]
  112. #[ORM\Index(columns: ['phone''inn'], name'crm_clients_custom_idx')]
  113. #[Gedmo\TranslationEntity(class: TranslationEntity::class)]
  114. class ClientEntity extends UserEntity implements PasswordAuthenticatedUserInterface
  115. {
  116.     // Пароль
  117.     #[ORM\Column(typeTypes::STRINGlength255nullablefalse)]
  118.     private string $password;
  119.     // Активность
  120.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => true])]
  121.     #[Groups(['read'])]
  122.     private bool $isActive true;
  123.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  124.     #[Groups(['read'])]
  125.     private bool $isTest false;
  126.     // Имя
  127.     #[ORM\Column(typeTypes::STRINGlength150nullabletrue)]
  128.     // #[Gedmo\Translatable]
  129.     #[Groups(['read'])]
  130.     private ?string $name null;
  131.     
  132.     // Фамилия
  133.     #[ORM\Column(typeTypes::STRINGlength150nullabletrue)]
  134.     // #[Gedmo\Translatable]
  135.     #[Groups(['read'])]
  136.     private ?string $lastName null;
  137.     // Отчество
  138.     #[ORM\Column(typeTypes::STRINGlength150nullabletrue)]
  139.     // #[Gedmo\Translatable]
  140.     #[Groups(['read'])]
  141.     private ?string $patronymic null;
  142.     // ФИО
  143.     #[Groups(['read'])]
  144.     public $fio null;
  145.     // Статус
  146.     #[ORM\ManyToOne(targetEntityStatusEntity::class)]
  147.     #[ORM\JoinColumn(name'status_id'referencedColumnName'id'nullabletrue)]
  148.     #[Groups(['read'])]
  149.     private ?StatusEntity $status null;
  150.     // Департамент
  151.     #[ORM\ManyToOne(targetEntityDepartmentEntity::class)]
  152.     #[ORM\JoinColumn(name'department_id'referencedColumnName'id'nullabletrue)]
  153.     #[Groups(['read'])]
  154.     private ?DepartmentEntity $department null;
  155.     // Тип верификации
  156.     #[ORM\ManyToOne(targetEntityVerificationTypeEntity::class)]
  157.     #[ORM\JoinColumn(name'verification_type_id'referencedColumnName'id'nullabletrue)]
  158.     #[Groups(['read'])]
  159.     private ?VerificationTypeEntity $verificationType null;
  160.     // Дата рождения
  161.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLEnullabletrue)]
  162.     #[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
  163.     #[Groups(['read'])]
  164.     private ?\DateTimeInterface $dateBirth null;
  165.     // Пол
  166.     #[ORM\ManyToOne(targetEntityGenderEntity::class)]
  167.     #[ORM\JoinColumn(name'gender_id'referencedColumnName'id'nullabletrue)]
  168.     #[Groups(['read'])]
  169.     private ?GenderEntity $gender null;
  170.     // Почта
  171.     #[ORM\Column(typeTypes::STRINGlength150nullabletrue)]
  172.     #[Groups(['read'])]
  173.     private ?string $email null;
  174.     // Дополнительные телефоны
  175.     #[ORM\Column(typeTypes::SIMPLE_ARRAYnullabletrue)]
  176.     #[Groups(['read'])]
  177.     private ?array $additionalPhones null;
  178.      
  179.     // Игнорировать финансовый мониторинг
  180.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  181.     #[Groups(['read'])]
  182.     private bool $isIgnoreFinancialMonitoring false;
  183.     // Адрес регистрации, населенный пункт
  184.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  185.     // #[Gedmo\Translatable]
  186.     #[Groups(['read'])]
  187.     private ?string $registrationLocality null;
  188.     // Адрес регистрации, улица
  189.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  190.     // #[Gedmo\Translatable]
  191.     #[Groups(['read'])]
  192.     private ?string $registrationStreet null;
  193.     // Адрес регистрации, номер дома
  194.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  195.     // #[Gedmo\Translatable]
  196.     #[Groups(['read'])]
  197.     private ?string $registrationHouseNumber null;
  198.     // Адрес регистрации, номер квартиры
  199.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  200.     // #[Gedmo\Translatable]
  201.     #[Groups(['read'])]
  202.     private ?string $registrationRoomNumber null;
  203.     // Фото
  204.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  205.     #[Groups(['read'])]
  206.     private ?string $photo null;
  207.     // ИНН
  208.     #[ORM\Column(typeTypes::STRINGlength150nullabletrue)]
  209.     #[Groups(['read'])]
  210.     private ?string $inn null;
  211.     // Тип документа/паспорта
  212.     #[ORM\ManyToOne(targetEntityDocumentTypeEntity::class)]
  213.     #[ORM\JoinColumn(name'document_type_id'referencedColumnName'id'nullabletrue)]
  214.     #[Groups(['read'])]
  215.     private ?DocumentTypeEntity $documentType null;
  216.     // Номер документа/паспорта
  217.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  218.     #[Groups(['read'])]
  219.     private ?string $documentId null;
  220.     // Кем выдан документ/паспорт
  221.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  222.     // #[Gedmo\Translatable]
  223.     #[Groups(['read'])]
  224.     private ?string $documentIssuingAuthority null;
  225.     // Дата выдачи документа/паспорта
  226.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLEnullabletrue)]
  227.     #[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
  228.     #[Groups(['read'])]
  229.     private ?\DateTimeInterface $documentIssueDate null;
  230.     // Версии мобильного приложения
  231.     #[ORM\ManyToOne(targetEntityMobileAppVersionEntity::class)]
  232.     #[ORM\JoinColumn(name'mobile_app_version_id'referencedColumnName'id'nullabletrue)]
  233.     #[Groups(['read'])]
  234.     #[MaxDepth(1)]
  235.     private ?MobileAppVersionEntity $appVersion null;
  236.     // Количество бонусов
  237.     #[Groups(['read'])]
  238.     public ?int $bonuses 0;
  239.     // Реферальный код
  240.     #[Groups(['read'])]
  241.     public ?string $referrerCode null;
  242.     // Реферер (вербующий клиент)
  243.     #[ORM\ManyToOne(targetEntityClientEntity::class)]
  244.     #[ORM\JoinColumn(name'referrer_сlient_id'referencedColumnName'id'nullabletrue)]
  245.     #[Groups(['read'])]
  246.     #[MaxDepth(1)]
  247.     private ?ClientEntity $referrerClient null;
  248.     // Информация о верификации
  249.     #[ORM\Column(typeTypes::STRINGlength150nullabletrue)]
  250.     #[Groups(['read'])]
  251.     private ?string $verificationInformation null;
  252.     // Подтвержден лимит
  253.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  254.     #[Groups(['read'])]
  255.     private bool $isLimitConfirmed false;
  256.     // Дата подтверждения лимита
  257.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLEnullabletrue)]
  258.     #[Context(
  259.         normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'],
  260.         denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
  261.     )]
  262.     #[Groups(['read'])]
  263.     private ?\DateTimeInterface $dateLimitConfirmed null;
  264.     /**
  265.      * Used locale to override Translation listener`s locale
  266.      * this is not a mapped field of entity metadata, just a simple property
  267.      */
  268.     #[Gedmo\Locale]
  269.     private $locale;
  270.     public function getPassword(): string
  271.     {
  272.         return (string) $this->password;
  273.     }
  274.     public function setPassword(string $password): void
  275.     {
  276.         $this->password $password;
  277.     }
  278.     public function getIsActive()
  279.     {
  280.         return $this->isActive;
  281.     }
  282.  
  283.     public function setIsActive($value)
  284.     {
  285.         $this->isActive $value;
  286.         return $this;
  287.     }
  288.     public function getIsTest(): bool
  289.     {
  290.         return $this->isTest;
  291.     }
  292.  
  293.     public function setIsTest(bool $value): self
  294.     {
  295.         $this->isTest $value;
  296.         return $this;
  297.     }
  298.     public function getName()
  299.     {
  300.         return $this->name;
  301.     }
  302.     public function setName($name)
  303.     {
  304.         $this->name $name;
  305.         return $this;
  306.     }
  307.  
  308.     public function getLastName()
  309.     {
  310.         return $this->lastName;
  311.     }
  312.     public function setLastName($lastName)
  313.     {
  314.         $this->lastName $lastName;
  315.         return $this;
  316.     }
  317.     public function getPatronymic()
  318.     {
  319.         return $this->patronymic;
  320.     }
  321.     public function setPatronymic($patronymic)
  322.     {
  323.         $this->patronymic $patronymic;
  324.         return $this;
  325.     }
  326.     public function getFIO()
  327.     {
  328.         $fio '';
  329.         if (!empty($this->lastName) && $this->lastName !== null)
  330.             $fio.= ' '.$this->lastName;
  331.         if (!empty($this->name) && $this->name !== null)
  332.             $fio.= ' '.$this->name;
  333.         if (!empty($this->patronymic) && $this->patronymic !== null)
  334.             $fio.= ' '.$this->patronymic;
  335.         return $this->fio trim($fio);
  336.     }
  337.     public function getStatus()
  338.     {
  339.         return $this->status;
  340.     }
  341.     public function setStatus($status)
  342.     {
  343.         $this->status $status;
  344.         return $this;
  345.     }
  346.     public function getDepartment()
  347.     {
  348.         return $this->department;
  349.     }
  350.     public function setDepartment($department)
  351.     {
  352.         $this->department $department;
  353.         return $this;
  354.     }
  355.     public function getVerificationType()
  356.     {
  357.         return $this->verificationType;
  358.     }
  359.     public function setVerificationType($type)
  360.     {
  361.         $this->verificationType $type;
  362.         return $this;
  363.     }
  364.     public function setDateBirth(\DateTimeImmutable|null $date)
  365.     {
  366.         $this->dateBirth $date;
  367.         return $this;
  368.     }
  369.     public function getDateBirth()
  370.     {
  371.         return $this->dateBirth;
  372.     }
  373.     public function getRoles(): array
  374.     {
  375.         $roles $this->roles;
  376.         // guarantee every user at least has ROLE_USER_CLIENT
  377.         $roles[] = 'ROLE_USER_CLIENT';
  378.         return \array_unique($roles);
  379.     }
  380.     public function getGender()
  381.     {
  382.         return $this->gender;
  383.     }
  384.     public function setGender($gender)
  385.     {
  386.         $this->gender $gender;
  387.         return $this;
  388.     }
  389.     public function setEmail($email)
  390.     {
  391.         $this->email $email;
  392.         return $this;
  393.     }
  394.     public function getEmail()
  395.     {
  396.         return $this->email;
  397.     }
  398.     public function getAdditionalPhones()
  399.     {
  400.         $phones $this->additionalPhones;
  401.         return ((!empty($phones) && count($phones)>0) ? \array_unique($phones) : null);
  402.     }
  403.     public function setAdditionalPhones($phones)
  404.     {
  405.         if (!empty($phones) && count($phones)>0)
  406.         {
  407.             foreach ($phones as &$phone)
  408.             {
  409.                 $phone = (!empty($phone))
  410.                     ? FormattingUtil::phoneNumber($phone)
  411.                     : null;
  412.             }
  413.             $phones \array_unique($phones);
  414.         }
  415.         $this->additionalPhones $phones;
  416.         return $this;
  417.     }
  418.     public function getIsIgnoreFinancialMonitoring()
  419.     {
  420.         return $this->isIgnoreFinancialMonitoring;
  421.     }
  422.  
  423.     public function setIsIgnoreFinancialMonitoring($value)
  424.     {
  425.         $this->isIgnoreFinancialMonitoring $value;
  426.         return $this;
  427.     }
  428.     public function getPhoto()
  429.     {
  430.         return $this->photo;
  431.     }
  432.     public function setPhoto($photo)
  433.     {
  434.         $this->photo $photo;
  435.         return $this;
  436.     }
  437.     public function getRegistrationLocality()
  438.     {
  439.         return $this->registrationLocality;
  440.     }
  441.     public function setRegistrationLocality($locality)
  442.     {
  443.         $this->registrationLocality $locality;
  444.         return $this;
  445.     }
  446.     public function getRegistrationStreet()
  447.     {
  448.         return $this->registrationStreet;
  449.     }
  450.     public function setRegistrationStreet($street)
  451.     {
  452.         $this->registrationStreet $street;
  453.         return $this;
  454.     }
  455.     public function getRegistrationHouseNumber()
  456.     {
  457.         return $this->registrationHouseNumber;
  458.     }
  459.     public function setRegistrationHouseNumber($number)
  460.     {
  461.         $this->registrationHouseNumber $number;
  462.         return $this;
  463.     }
  464.     public function getRegistrationRoomNumber()
  465.     {
  466.         return $this->registrationRoomNumber;
  467.     }
  468.     public function setRegistrationRoomNumber($number)
  469.     {
  470.         $this->registrationRoomNumber $number;
  471.         return $this;
  472.     }
  473.     public function getInn()
  474.     {
  475.         return $this->inn;
  476.     }
  477.     public function setInn($inn)
  478.     {
  479.         $this->inn $inn;
  480.         return $this;
  481.     }
  482.     public function getDocumentType()
  483.     {
  484.         return $this->documentType;
  485.     }
  486.     public function setDocumentType($type)
  487.     {
  488.         $this->documentType $type;
  489.         return $this;
  490.     }
  491.     public function getDocumentId()
  492.     {
  493.         return $this->documentId;
  494.     }
  495.     public function setDocumentId($value)
  496.     {
  497.         $this->documentId $value;
  498.         return $this;
  499.     }
  500.     public function getDocumentIssuingAuthority()
  501.     {
  502.         return $this->documentIssuingAuthority;
  503.     }
  504.     public function setDocumentIssuingAuthority($value)
  505.     {
  506.         $this->documentIssuingAuthority $value;
  507.         return $this;
  508.     }
  509.     public function setDocumentIssueDate(\DateTimeImmutable|null $date)
  510.     {
  511.         $this->documentIssueDate $date;
  512.         return $this;
  513.     }
  514.     public function getDocumentIssueDate()
  515.     {
  516.         return $this->documentIssueDate;
  517.     }
  518.     public function getAppVersion()
  519.     {
  520.         return $this->appVersion;
  521.     }
  522.     public function setAppVersion($version)
  523.     {
  524.         $this->appVersion $version;
  525.         return $this;
  526.     }
  527.     public function getReferrerClient()
  528.     {
  529.         return $this->referrerClient;
  530.     }
  531.     public function setReferrerClient($client)
  532.     {
  533.         $this->referrerClient $client;
  534.         return $this;
  535.     }
  536.     public function getVerificationInformation()
  537.     {
  538.         return $this->verificationInformation;
  539.     }
  540.     public function setVerificationInformation($information)
  541.     {
  542.         $this->verificationInformation $information;
  543.         return $this;
  544.     }
  545.     public function getIsLimitConfirmed()
  546.     {
  547.         return $this->isLimitConfirmed;
  548.     }
  549.  
  550.     public function setIsLimitConfirmed($value)
  551.     {
  552.         $this->isLimitConfirmed $value;
  553.         return $this;
  554.     }
  555.     public function setDateLimitConfirmed(\DateTimeImmutable|null $date)
  556.     {
  557.         $this->dateLimitConfirmed $date;
  558.         return $this;
  559.     }
  560.     public function getDateLimitConfirmed()
  561.     {
  562.         return $this->dateLimitConfirmed;
  563.     }
  564.     public function setTranslatableLocale($locale)
  565.     {
  566.         $this->locale $locale;
  567.     }
  568. }