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