src/Containers/CrmSection/PaymentContainer/Entities/PaymentEntity.php line 101

Open in your IDE?
  1. <?php
  2. namespace App\Containers\CrmSection\PaymentContainer\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\PaymentContainer\Data\Repositories\PaymentRepository;
  25. use App\Containers\SettingSection\ListContainer\Entities\StatusEntity;
  26. use App\Containers\SettingSection\ListContainer\Entities\PaymentTypeEntity;
  27. use App\Containers\CrmSection\ClientContainer\Entities\ClientEntity;
  28. use App\Containers\CrmSection\CarContainer\Entities\CarEntity;
  29. use App\Containers\CrmSection\ContractContainer\Entities\ContractEntity;
  30. use App\Containers\CrmSection\ContractContainer\Entities\AgreementEntity;
  31. use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
  32. /** 
  33.  * Оплата
  34. */
  35. #[ApiResource(
  36.     routePrefix'/crm',
  37.     normalizationContext: [
  38.         'groups' => 'read',
  39.         'enable_max_depth' => true
  40.     ],
  41.     operations: [
  42.         new Get(
  43.             uriTemplate'/payments/{id}'requirements: ['id' => '\d+'],
  44.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  45.         ),
  46.         new Patch(
  47.             uriTemplate'/payments/{id}'requirements: ['id' => '\d+'],
  48.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  49.         ),
  50.         // new Put(
  51.         //     uriTemplate: '/payments/{id}', requirements: ['id' => '\d+'],
  52.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  53.         // ),
  54.         new Delete(
  55.             uriTemplate'/payments/{id}'requirements: ['id' => '\d+'],
  56.             security"is_granted('ROLE_ADMIN')"
  57.         ),
  58.         // new Post(
  59.         //     uriTemplate: '/payments',
  60.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  61.         // ),
  62.         new GetCollection(
  63.             uriTemplate'/payments',
  64.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  65.         ),
  66.     ],
  67.     shortName'CRM_Payments'
  68. )]
  69. #[ApiFilter(SearchFilter::class, properties: [
  70.     'id' => 'exact'
  71.     'externalCode' => 'partial',
  72.     'client' => 'exact',
  73.     'contract' => 'exact',
  74.     'agreement' => 'exact',
  75.     'paymentType' => 'exact',
  76.     'status' => 'exact',
  77.     'number' => 'partial'
  78.     'paymentType.name' => 'partial'
  79.     'paymentType.externalCode' => 'partial'
  80.     'status.id' => 'exact',
  81.     'status.name' => 'partial',
  82.     'status.externalCode' => 'exact',
  83.     'comment' => 'partial',
  84.     'error' => 'exact',
  85.     'purpose' => 'exact',
  86.     'merchantGUID' => 'exact',
  87.     'externalCodePaymentSystem' => 'exact',
  88. ])]
  89. #[ApiFilter(NumericFilter::class, properties: ['id''paymentRepeatedAttempt''paymentType.id''client.id''contract.id''agreement.id''car.id'])]
  90. #[ApiFilter(RangeFilter::class, properties: ['id''paymentUAH''paymentRepeatedAttempt''paymentType.id''client.id''contract.id''agreement.id''car.id'])]
  91. #[ApiFilter(DateFilter::class, properties: ['dateIssue''datePayment''dateError'])]
  92. #[ApiFilter(BooleanFilter::class, properties: ['isAutoPayment''isAutoPaymentRepeated''isHide'])]
  93. #[ApiFilter(OrderFilter::class)]
  94. #[ApiFilter(filterClassSimpleSearchFilter::class, properties: ['number''comment'])]
  95. #[ORM\Entity(repositoryClassPaymentRepository::class)]
  96. #[ORM\Table(name'`crm_payments`')]
  97. #[ORM\Index(columns: ['number'], name'crm_payments_custom_idx')]
  98. class PaymentEntity
  99. {
  100.     #[ORM\Id]
  101.     #[ORM\GeneratedValue]
  102.     #[ORM\Column(typeTypes::INTEGER)]
  103.     #[Groups(['read'])]
  104.     private ?int $id null;
  105.     // Внешний код
  106.     #[ORM\Column(typeTypes::STRINGlength255nullabletrueuniquetrue)]
  107.     #[Groups(['read'])]
  108.     private ?string $externalCode null;
  109.     // Номер счета
  110.     #[ORM\Column(typeTypes::STRINGlength50nullabletrueuniquetrue)]
  111.     #[Groups(['read'])]
  112.     private ?string $number null;
  113.     // Дата выставления
  114.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLEnullabletrue)]
  115.     #[Context(
  116.         normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'],
  117.         denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
  118.     )]
  119.     #[Groups(['read'])]
  120.     private ?\DateTimeInterface $dateIssue null;
  121.     // Клиент
  122.     #[ORM\ManyToOne(targetEntityClientEntity::class)]
  123.     #[ORM\JoinColumn(name'client_id'referencedColumnName'id'nullablefalse)]
  124.     #[Groups(['read'])]
  125.     private ClientEntity $client;
  126.     // Договор
  127.     #[ORM\ManyToOne(targetEntityContractEntity::class)]
  128.     #[ORM\JoinColumn(name'contract_id'referencedColumnName'id'nullablefalse)]
  129.     #[Groups(['read'])]
  130.     #[MaxDepth(1)]
  131.     private ContractEntity $contract;
  132.     // Доп. соглашение
  133.     #[ORM\ManyToOne(targetEntityAgreementEntity::class)]
  134.     #[ORM\JoinColumn(name'agreement_id'referencedColumnName'id'nullabletrue)]
  135.     #[Groups(['read'])]
  136.     #[MaxDepth(1)]
  137.     private ?AgreementEntity $agreement null;
  138.     // Тип оплаты
  139.     #[ORM\ManyToOne(targetEntityPaymentTypeEntity::class)]
  140.     #[ORM\JoinColumn(name'payment_type_id'referencedColumnName'id'nullablefalse)]
  141.     #[Groups(['read'])]
  142.     private PaymentTypeEntity $paymentType;
  143.     // Количество километража
  144.     #[ORM\Column(typeTypes::INTEGERlength10options: ['default' => 0])]
  145.     #[Groups(['read'])]
  146.     private ?int $mileage 0;
  147.     // Статус
  148.     #[ORM\ManyToOne(targetEntityStatusEntity::class)]
  149.     #[ORM\JoinColumn(name'status_id'referencedColumnName'id'nullabletrue)]
  150.     #[Groups(['read'])]
  151.     private ?StatusEntity $status null;
  152.     // Дата оплаты
  153.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLEnullabletrue)]
  154.     #[Context(
  155.         normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'],
  156.         denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
  157.     )]
  158.     #[Groups(['read'])]
  159.     private ?\DateTimeInterface $datePayment null;
  160.     // Сумма платежа в ГРН
  161.     #[ORM\Column(typeTypes::FLOATscale3nullablefalse)]
  162.     #[Groups(['read'])]
  163.     private float $paymentUAH;
  164.     // Назначение платежа
  165.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  166.     #[Groups(['read'])]
  167.     private ?string $purpose null;
  168.     // Автоматическая оплата
  169.     #[ORM\Column(typeTypes::BOOLEAN)]
  170.     #[Groups(['read'])]
  171.     private ?bool $isAutoPayment false;
  172.     // Повторне автосписання
  173.     #[ORM\Column(typeTypes::BOOLEAN)]
  174.     #[Groups(['read'])]
  175.     private ?bool $isAutoPaymentRepeated false;
  176.     // Спроба автосписання
  177.     #[ORM\Column(typeTypes::INTEGERlength10options: ['default' => 0])]
  178.     #[Groups(['read'])]
  179.     private ?int $paymentRepeatedAttempt 0;
  180.     // Код оплаты с платежной системы
  181.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  182.     #[Groups(['read'])]
  183.     private ?string $externalCodePaymentSystem null;
  184.     // GUID оплаты в платежной системе
  185.     #[ORM\Column(typeTypes::STRINGlength255nullabletrueuniquetrue)]
  186.     private ?string $merchantGUID null;
  187.     // Комментарий
  188.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  189.     #[Groups(['read'])]
  190.     private ?string $comment null;
  191.     // Дата получения ошибки
  192.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLEnullabletrue)]
  193.     #[Context(
  194.         normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'],
  195.         denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
  196.     )]
  197.     #[Groups(['read'])]
  198.     private ?\DateTimeInterface $dateError null;
  199.     // Ошибка
  200.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  201.     #[Groups(['read'])]
  202.     private ?string $error null;
  203.     // Автомобиль
  204.     #[ORM\ManyToOne(targetEntityCarEntity::class)]
  205.     #[ORM\JoinColumn(name'car_id'referencedColumnName'id'nullabletrue)]
  206.     #[MaxDepth(2)]
  207.     #[Groups(['read'])]
  208.     private ?CarEntity $car null;
  209.     // Скрыть
  210.     #[ORM\Column(typeTypes::BOOLEAN)]
  211.     #[Groups(['read'])]
  212.     private ?bool $isHide false;
  213.     #[Gedmo\Timestampable(on'create')]
  214.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  215.     #[Context(
  216.         normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
  217.     )]
  218.     #[Groups(['read'])]
  219.     protected $createdAt;
  220.     #[Gedmo\Timestampable(on'update')]
  221.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  222.     #[Context(
  223.         normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
  224.     )]
  225.     #[Groups(['read'])]
  226.     protected $updatedAt;
  227.     public function getId(): ?int
  228.     {
  229.         return $this->id;
  230.     }
  231.     public function getExternalCode()
  232.     {
  233.         return $this->externalCode;
  234.     }
  235.     public function setExternalCode($code)
  236.     {
  237.         $this->externalCode $code;
  238.         return $this;
  239.     }
  240.     public function getNumber()
  241.     {
  242.         return $this->number;
  243.     }
  244.     public function setNumber($number)
  245.     {
  246.         $this->number $number;
  247.         return $this;
  248.     }
  249.     
  250.     public function setDateIssue(\DateTimeImmutable|null $date)
  251.     {
  252.         $this->dateIssue $date;
  253.         return $this;
  254.     }
  255.     public function getDateIssue()
  256.     {
  257.         return $this->dateIssue;
  258.     }
  259.     public function getClient()
  260.     {
  261.         return $this->client;
  262.     }
  263.     public function setClient($client)
  264.     {
  265.         $this->client $client;
  266.         return $this;
  267.     }
  268.     public function getContract()
  269.     {
  270.         return $this->contract;
  271.     }
  272.     public function setContract($contract)
  273.     {
  274.         $this->contract $contract;
  275.         return $this;
  276.     }
  277.     public function getAgreement()
  278.     {
  279.         return $this->agreement;
  280.     }
  281.     public function setAgreement($agreement)
  282.     {
  283.         $this->agreement $agreement;
  284.         return $this;
  285.     }
  286.     public function getPaymentType()
  287.     {
  288.         return $this->paymentType;
  289.     }
  290.     public function setPaymentType($type)
  291.     {
  292.         $this->paymentType $type;
  293.         return $this;
  294.     }
  295.     public function getMileage()
  296.     {
  297.         return $this->mileage;
  298.     }
  299.  
  300.     public function setMileage($mileage)
  301.     {
  302.         $this->mileage $mileage;
  303.         return $this;
  304.     }
  305.     public function getStatus()
  306.     {
  307.         return $this->status;
  308.     }
  309.     public function setStatus($status)
  310.     {
  311.         $this->status $status;
  312.         return $this;
  313.     }
  314.     public function setDatePayment(\DateTimeImmutable|null $date)
  315.     {
  316.         $this->datePayment $date;
  317.         return $this;
  318.     }
  319.     public function getDatePayment()
  320.     {
  321.         return $this->datePayment;
  322.     }
  323.     public function getPaymentUAH()
  324.     {
  325.         return $this->paymentUAH;
  326.     }
  327.     public function setPaymentUAH($value)
  328.     {
  329.         $this->paymentUAH = ($value !== null round($value3) : null);
  330.         return $this;
  331.     }
  332.     public function getPurpose()
  333.     {
  334.         return $this->purpose;
  335.     }
  336.     public function setPurpose($purpose)
  337.     {
  338.         $this->purpose $purpose;
  339.         return $this;
  340.     }
  341.     public function getIsAutoPayment()
  342.     {
  343.         return $this->isAutoPayment;
  344.     }
  345.  
  346.     public function setIsAutoPayment($value)
  347.     {
  348.         $this->isAutoPayment $value;
  349.         return $this;
  350.     }
  351.     public function getIsAutoPaymentRepeated()
  352.     {
  353.         return $this->isAutoPaymentRepeated;
  354.     }
  355.  
  356.     public function setIsAutoPaymentRepeated(?bool $value)
  357.     {
  358.         $this->isAutoPaymentRepeated $value;
  359.         return $this;
  360.     }
  361.     public function getPaymentRepeatedAttempt()
  362.     {
  363.         return $this->paymentRepeatedAttempt;
  364.     }
  365.  
  366.     public function setPaymentRepeatedAttempt(?int $mileage)
  367.     {
  368.         $this->paymentRepeatedAttempt $mileage;
  369.         return $this;
  370.     }
  371.     public function getExternalCodePaymentSystem()
  372.     {
  373.         return $this->externalCodePaymentSystem;
  374.     }
  375.     public function setExternalCodePaymentSystem($code)
  376.     {
  377.         $this->externalCodePaymentSystem $code;
  378.         return $this;
  379.     }
  380.     public function getMerchantGUID()
  381.     {
  382.         return $this->merchantGUID;
  383.     }
  384.     public function setMerchantGUID($guid)
  385.     {
  386.         $this->merchantGUID $guid;
  387.         return $this;
  388.     }
  389.     public function getComment()
  390.     {
  391.         return $this->comment;
  392.     }
  393.     public function setComment($comment)
  394.     {
  395.         $this->comment $comment;
  396.         return $this;
  397.     }
  398.     public function setDateError(\DateTimeImmutable|null $date)
  399.     {
  400.         $this->dateError $date;
  401.         return $this;
  402.     }
  403.     public function getDateError()
  404.     {
  405.         return $this->dateError;
  406.     }
  407.     public function getError()
  408.     {
  409.         return $this->error;
  410.     }
  411.     public function setError($error)
  412.     {
  413.         $this->error $error;
  414.         return $this;
  415.     }
  416.     public function getCar()
  417.     {
  418.         return $this->car;
  419.     }
  420.     public function setCar($car)
  421.     {
  422.         $this->car $car;
  423.         return $this;
  424.     }
  425.     public function getIsHide()
  426.     {
  427.         return $this->isHide;
  428.     }
  429.     public function setIsHide($value)
  430.     {
  431.         $this->isHide $value;
  432.         return $this;
  433.     }
  434.     public function getCreatedAt()
  435.     {
  436.         return $this->createdAt;
  437.     }
  438.     public function getUpdatedAt()
  439.     {
  440.         return $this->updatedAt;
  441.     }    
  442. }