src/Containers/CrmSection/BonusSystemContainer/Entities/TransactionEntity.php line 93

Open in your IDE?
  1. <?php
  2. namespace App\Containers\CrmSection\BonusSystemContainer\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 App\Containers\CrmSection\BonusSystemContainer\Data\Repositories\TransactionRepository;
  25. use App\Containers\SettingSection\ListContainer\Entities\BonusTypeEntity;
  26. use App\Containers\SettingSection\ListContainer\Entities\BonusTransactionTypeEntity;
  27. use App\Containers\CrmSection\ClientContainer\Entities\ClientEntity;
  28. use App\Containers\CrmSection\ContractContainer\Entities\ContractEntity;
  29. use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
  30. /** 
  31.  * Транзакции
  32. */
  33. #[ApiResource(
  34.     routePrefix'/crm',
  35.     normalizationContext: [
  36.         'groups' => 'read',
  37.         'enable_max_depth' => true
  38.     ],
  39.     operations: [
  40.         new Get(
  41.             uriTemplate'/bonus_transactions/{id}'requirements: ['id' => '\d+'],
  42.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  43.         ),
  44.         new Patch(
  45.             uriTemplate'/bonus_transactions/{id}'requirements: ['id' => '\d+'],
  46.             security"is_granted('ROLE_ADMIN')"
  47.         ),
  48.         // new Put(
  49.         //     uriTemplate: '/bonus_transactions/{id}', requirements: ['id' => '\d+'],
  50.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  51.         // ),
  52.         new Delete(
  53.             uriTemplate'/bonus_transactions/{id}'requirements: ['id' => '\d+'],
  54.             security"is_granted('ROLE_ADMIN')"
  55.         ),
  56.         new Post(
  57.             uriTemplate'/bonus_transactions',
  58.             security"is_granted('ROLE_ADMIN')"
  59.         ),
  60.         new GetCollection(
  61.             uriTemplate'/bonus_transactions',
  62.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  63.         ),
  64.     ],
  65.     shortName'CRM_BonusSystem'
  66. )]
  67. #[ApiFilter(SearchFilter::class, properties: [
  68.     'id' => 'exact'
  69.     'externalCode' => 'partial',
  70.     'bonusType' => 'exact',
  71.     'client' => 'exact',
  72.     'referrer' => 'exact',
  73.     'type' => 'exact',
  74.     'contract' => 'exact',
  75.     'comment' => 'partial',
  76.     'type.id' => 'exact',
  77.     'type.name' => 'partial',
  78.     'type.code' => 'exact',
  79.     'bonusType.id' => 'exact',
  80.     'bonusType.name' => 'partial',
  81.     'bonusType.code' => 'exact',
  82. ])]
  83. #[ApiFilter(NumericFilter::class, properties: ['id''bonuses''bonusType.id''type.id''client.id''referrer.id''contract.id'])]
  84. #[ApiFilter(RangeFilter::class, properties: ['id''bonuses''bonusType.id''type.id''client.id''referrer.id''contract.id'])]
  85. #[ApiFilter(DateFilter::class, properties: ['date''createdAt''updatedAt'])]
  86. #[ApiFilter(OrderFilter::class)]
  87. #[ApiFilter(filterClassSimpleSearchFilter::class, properties: ['comment'])]
  88. #[ORM\Entity(repositoryClassTransactionRepository::class)]
  89. #[ORM\Table(name'`crm_bonus_transactions`')]
  90. class TransactionEntity
  91. {
  92.     #[ORM\Id]
  93.     #[ORM\GeneratedValue]
  94.     #[ORM\Column(typeTypes::INTEGER)]
  95.     #[Groups(['read'])]
  96.     private ?int $id null;
  97.     // Внешний код
  98.     #[ORM\Column(typeTypes::STRINGlength255nullabletrueuniquetrue)]
  99.     #[Groups(['read'])]
  100.     private ?string $externalCode null;
  101.     // Тип бонуса
  102.     #[ORM\ManyToOne(targetEntityBonusTypeEntity::class)]
  103.     #[ORM\JoinColumn(name'bonus_type_id'referencedColumnName'id'nullabletrue)]
  104.     #[Groups(['read'])]
  105.     #[MaxDepth(1)]
  106.     private ?BonusTypeEntity $bonusType null;
  107.     // Клиент/Реферал
  108.     #[ORM\ManyToOne(targetEntityClientEntity::class)]
  109.     #[ORM\JoinColumn(name'client_id'referencedColumnName'id'nullablefalse)]
  110.     #[Groups(['read'])]
  111.     #[MaxDepth(2)]
  112.     private ClientEntity $client;
  113.     // Реферер (вербующий клиент)
  114.     #[ORM\ManyToOne(targetEntityClientEntity::class)]
  115.     #[ORM\JoinColumn(name'referrer_id'referencedColumnName'id'nullabletrue)]
  116.     #[Groups(['read'])]
  117.     #[MaxDepth(2)]
  118.     private ?ClientEntity $referrer null;
  119.     // Тип транзакций
  120.     #[ORM\ManyToOne(targetEntityBonusTransactionTypeEntity::class)]
  121.     #[ORM\JoinColumn(name'type_id'referencedColumnName'id'nullablefalse)]
  122.     #[Groups(['read'])]
  123.     #[MaxDepth(1)]
  124.     private BonusTransactionTypeEntity $type;
  125.     // Дата транзакции
  126.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLEnullabletrue)]
  127.     #[Context(
  128.         normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'],
  129.         denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
  130.     )]
  131.     #[Groups(['read'])]
  132.     private ?\DateTimeInterface $date null;
  133.     // Количество бонусов
  134.     #[ORM\Column(typeTypes::INTEGERlength10options: ['default' => 0])]
  135.     #[Groups(['read'])]
  136.     private ?int $bonuses 0;
  137.     // Договор
  138.     #[ORM\ManyToOne(targetEntityContractEntity::class)]
  139.     #[ORM\JoinColumn(name'contract_id'referencedColumnName'id'nullabletrue)]
  140.     #[Groups(['read'])]
  141.     #[MaxDepth(2)]
  142.     private ?ContractEntity $contract null;
  143.     // Комментарий
  144.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  145.     #[Groups(['read'])]
  146.     private ?string $comment null;
  147.     #[Gedmo\Timestampable(on'create')]
  148.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  149.     #[Groups(['read'])]
  150.     protected $createdAt;
  151.     #[Gedmo\Timestampable(on'update')]
  152.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  153.     #[Groups(['read'])]
  154.     protected $updatedAt;
  155.     public function getId(): ?int
  156.     {
  157.         return $this->id;
  158.     }
  159.     public function getExternalCode()
  160.     {
  161.         return $this->externalCode;
  162.     }
  163.     public function setExternalCode($code)
  164.     {
  165.         $this->externalCode $code;
  166.         return $this;
  167.     }
  168.     public function getBonusType()
  169.     {
  170.         return $this->bonusType;
  171.     }
  172.     public function setBonusType($type)
  173.     {
  174.         $this->bonusType $type;
  175.         return $this;
  176.     }
  177.     public function getClient()
  178.     {
  179.         return $this->client;
  180.     }
  181.     public function setClient($client)
  182.     {
  183.         $this->client $client;
  184.         return $this;
  185.     }
  186.     public function getReferrer()
  187.     {
  188.         return $this->referrer;
  189.     }
  190.     public function setReferrer($referrer)
  191.     {
  192.         $this->referrer $referrer;
  193.         return $this;
  194.     }
  195.     public function getType()
  196.     {
  197.         return $this->type;
  198.     }
  199.     public function setType($type)
  200.     {
  201.         $this->type $type;
  202.         return $this;
  203.     }
  204.     public function setDate(\DateTimeImmutable|null $date)
  205.     {
  206.         $this->date $date;
  207.         return $this;
  208.     }
  209.     public function getDate()
  210.     {
  211.         return $this->date;
  212.     }
  213.     public function getBonuses()
  214.     {
  215.         return $this->bonuses;
  216.     }
  217.  
  218.     public function setBonuses($bonuses)
  219.     {
  220.         $this->bonuses $bonuses;
  221.         return $this;
  222.     }
  223.     public function getContract()
  224.     {
  225.         return $this->contract;
  226.     }
  227.  
  228.     public function setContract($contract)
  229.     {
  230.         $this->contract $contract;
  231.         return $this;
  232.     }
  233.     public function getComment()
  234.     {
  235.         return $this->comment;
  236.     }
  237.     public function setComment($comment)
  238.     {
  239.         $this->comment $comment;
  240.         return $this;
  241.     }
  242.     public function getCreatedAt()
  243.     {
  244.         return $this->createdAt;
  245.     }
  246.     public function getUpdatedAt()
  247.     {
  248.         return $this->updatedAt;
  249.     }
  250. }