src/Containers/CrmSection/ContractContainer/Entities/AgreementEntity.php line 100

Open in your IDE?
  1. <?php
  2. namespace App\Containers\CrmSection\ContractContainer\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\ContractContainer\Data\Repositories\AgreementRepository;
  25. use App\Containers\CrmSection\ClientContainer\Entities\ClientEntity;
  26. use App\Containers\CrmSection\CarContainer\Entities\CarEntity;
  27. use App\Containers\CrmSection\ContractContainer\Entities\ContractEntity;
  28. use App\Containers\SettingSection\ListContainer\Entities\StatusEntity;
  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'/agreements/{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'/agreements/{id}'requirements: ['id' => '\d+'],
  46.             security"is_granted('ROLE_ADMIN')"
  47.         ),
  48.         // new Put(
  49.         //     uriTemplate: '/agreements/{id}', requirements: ['id' => '\d+'],
  50.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  51.         // ),
  52.         // new Delete(
  53.         //     uriTemplate: '/agreements/{id}', requirements: ['id' => '\d+'],
  54.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  55.         // ),
  56.         // new Post(
  57.         //     uriTemplate: '/agreements',
  58.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  59.         // ),
  60.         new GetCollection(
  61.             uriTemplate'/agreements',
  62.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  63.         ),
  64.     ],
  65.     shortName'CRM_Agreements'
  66. )]
  67. #[ApiFilter(SearchFilter::class, properties: [
  68.     'id' => 'exact'
  69.     'number' => 'partial'
  70.     'externalCode' => 'partial'
  71.     'status' => 'exact',
  72.     'contract' => 'exact',
  73.     'car' => 'exact',
  74.     'client' => 'exact'
  75.     'client.name' => 'partial'
  76.     'client.lastName' => 'partial'
  77.     'client.patronymic' => 'partial'
  78.     'client.externalCode' => 'partial'
  79.     'client.phone' => 'exact'
  80.     'client.email' => 'exact'
  81.     'client.inn' => 'exact'
  82.     'status' => 'exact'
  83.     'status.name' => 'exact'
  84.     'status.externalCode' => 'exact'
  85. ])]
  86. #[ApiFilter(NumericFilter::class, properties: ['id''paymentUAH'])]
  87. #[ApiFilter(RangeFilter::class, properties: ['id''mileage'])]
  88. #[ApiFilter(BooleanFilter::class, properties: ['isPaid''isAutoPayment''isSentTo1C'])]
  89. #[ApiFilter(DateFilter::class, properties: ['datePayment''dateConclusionAgreement'])]
  90. #[ApiFilter(OrderFilter::class)]
  91. #[ApiFilter(filterClassSimpleSearchFilter::class, properties: [
  92.     'number''externalCode'
  93. ])]
  94. #[ORM\Entity(repositoryClassAgreementRepository::class)]
  95. #[ORM\Table(name'`crm_agreements`')]
  96. #[ORM\Index(columns: ['number'], name'crm_agreements_custom_idx')]
  97. class AgreementEntity
  98. {   
  99.     #[ORM\Id]
  100.     #[ORM\GeneratedValue]
  101.     #[ORM\Column(typeTypes::INTEGER)]
  102.     #[Groups(['read'])]
  103.     private ?int $id null;
  104.     #[ORM\Column(typeTypes::STRINGlength255nullabletrueuniquetrue)]
  105.     #[Groups(['read'])]
  106.     private ?string $externalCode null;
  107.     // Номер соглашения
  108.     #[ORM\Column(typeTypes::STRINGlength50nullabletrueuniquetrue)]
  109.     #[Groups(['read'])]
  110.     private ?string $number null;
  111.     // Статус
  112.     #[ORM\ManyToOne(targetEntityStatusEntity::class)]
  113.     #[ORM\JoinColumn(name'status_id'referencedColumnName'id'nullablefalse)]
  114.     #[Groups(['read'])]
  115.     #[MaxDepth(1)]
  116.     private StatusEntity $status;
  117.     // Клиент
  118.     #[ORM\ManyToOne(targetEntityClientEntity::class)]
  119.     #[ORM\JoinColumn(name'client_id'referencedColumnName'id'nullablefalse)]
  120.     #[Groups(['read'])]
  121.     #[MaxDepth(2)]
  122.     private ClientEntity $client;
  123.     // Договор
  124.     #[ORM\ManyToOne(targetEntityContractEntity::class)]
  125.     #[ORM\JoinColumn(name'contract_id'referencedColumnName'id'nullablefalse)]
  126.     #[Groups(['read'])]
  127.     #[MaxDepth(2)]
  128.     private ContractEntity $contract;
  129.     // Количество километров
  130.     #[ORM\Column(typeTypes::INTEGERlength10options: ['default' => 0])]
  131.     #[Groups(['read'])]
  132.     private ?int $mileage 0;    
  133.     // Сумма платежа в ГРН
  134.     #[ORM\Column(typeTypes::FLOATscale3nullablefalse)]
  135.     #[Groups(['read'])]
  136.     private float $paymentUAH;
  137.     // Дата заключения доп. соглашения
  138.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLEnullabletrue)]
  139.     #[Context(
  140.         normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'],
  141.         denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
  142.     )]
  143.     #[Groups(['read'])]
  144.     private ?\DateTimeInterface $dateConclusionAgreement null;
  145.     // Дата оплаты
  146.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLEnullabletrue)]
  147.     #[Context(
  148.         normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'],
  149.         denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
  150.     )]
  151.     #[Groups(['read'])]
  152.     private ?\DateTimeInterface $datePayment null;
  153.     // Cоглашение оплачено
  154.     #[ORM\Column(typeTypes::BOOLEAN)]
  155.     #[Groups(['read'])]
  156.     private ?bool $isPaid false;
  157.     // Автоматическая оплата
  158.     #[ORM\Column(typeTypes::BOOLEAN)]
  159.     #[Groups(['read'])]
  160.     private ?bool $isAutoPayment false;
  161.     // Отправлен в 1С
  162.     #[ORM\Column(typeTypes::BOOLEAN)]
  163.     #[Groups(['read'])]
  164.     private ?bool $isSentTo1C false;
  165.     // Ошибка при отправке в 1С
  166.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  167.     #[Groups(['read'])]
  168.     private ?string $errorSentTo1C null;
  169.     // Автомобиль
  170.     #[ORM\ManyToOne(targetEntityCarEntity::class)]
  171.     #[ORM\JoinColumn(name'car_id'referencedColumnName'id'nullabletrue)]
  172.     #[MaxDepth(2)]
  173.     #[Groups(['read'])]
  174.     private ?CarEntity $car null;
  175.     // Скрыть
  176.     #[ORM\Column(typeTypes::BOOLEAN)]
  177.     #[Groups(['read'])]
  178.     private ?bool $isHide false;
  179.     #[Gedmo\Timestampable(on'create')]
  180.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  181.     #[Groups(['read'])]
  182.     protected $createdAt;
  183.     #[Gedmo\Timestampable(on'update')]
  184.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  185.     #[Groups(['read'])]
  186.     protected $updatedAt;
  187.     public function getId(): ?int
  188.     {
  189.         return $this->id;
  190.     }
  191.     public function getExternalCode()
  192.     {
  193.         return $this->externalCode;
  194.     }
  195.     public function setExternalCode($code)
  196.     {
  197.         $this->externalCode $code;
  198.         return $this;
  199.     }
  200.     public function getNumber()
  201.     {
  202.         return $this->number;
  203.     }
  204.     public function setNumber($number)
  205.     {
  206.         $this->number $number;
  207.         return $this;
  208.     }
  209.     public function getStatus()
  210.     {
  211.         return $this->status;
  212.     }
  213.     public function setStatus($status)
  214.     {
  215.         $this->status $status;
  216.         return $this;
  217.     }
  218.  
  219.     public function getClient()
  220.     {
  221.         return $this->client;
  222.     }
  223.     public function setClient($client)
  224.     {
  225.         $this->client $client;
  226.         return $this;
  227.     }
  228.     public function getContract()
  229.     {
  230.         return $this->contract;
  231.     }
  232.     public function setContract($contract)
  233.     {
  234.         $this->contract $contract;
  235.         return $this;
  236.     }
  237.     public function getMileage()
  238.     {
  239.         return $this->mileage;
  240.     }
  241.  
  242.     public function setMileage($mileage)
  243.     {
  244.         $this->mileage $mileage;
  245.         return $this;
  246.     }
  247.     public function getPaymentUAH()
  248.     {
  249.         return $this->paymentUAH;
  250.     }
  251.     public function setPaymentUAH($value)
  252.     {
  253.         $this->paymentUAH = ($value !== null round($value3) : null);
  254.         return $this;
  255.     }
  256.     public function setDateConclusionAgreement(\DateTimeImmutable|null $date)
  257.     {
  258.         $this->dateConclusionAgreement $date;
  259.         return $this;
  260.     }
  261.     public function getDateConclusionAgreement()
  262.     {
  263.         return $this->dateConclusionAgreement;
  264.     }
  265.     public function setDatePayment(\DateTimeImmutable|null $date)
  266.     {
  267.         $this->datePayment $date;
  268.         return $this;
  269.     }
  270.     public function getDatePayment()
  271.     {
  272.         return $this->datePayment;
  273.     }
  274.     public function getIsAutoPayment()
  275.     {
  276.         return $this->isAutoPayment;
  277.     }
  278.  
  279.     public function setIsAutoPayment($value)
  280.     {
  281.         $this->isAutoPayment $value;
  282.         return $this;
  283.     }
  284.     public function getIsPaid()
  285.     {
  286.         return $this->isPaid;
  287.     }
  288.  
  289.     public function setIsPaid($value)
  290.     {
  291.         $this->isPaid $value;
  292.         return $this;
  293.     }
  294.     public function getIsSentTo1C()
  295.     {
  296.         return $this->isSentTo1C;
  297.     }
  298.     public function setIsSentTo1C($value)
  299.     {
  300.         $this->isSentTo1C $value;
  301.         return $this;
  302.     }
  303.     public function getErrorSentTo1C()
  304.     {
  305.         return $this->errorSentTo1C;
  306.     }
  307.     public function setErrorSentTo1C($error)
  308.     {
  309.         $this->errorSentTo1C $error;
  310.         return $this;
  311.     }
  312.     public function getCar()
  313.     {
  314.         return $this->car;
  315.     }
  316.     public function setCar($car)
  317.     {
  318.         $this->car $car;
  319.         return $this;
  320.     }
  321.     public function getIsHide()
  322.     {
  323.         return $this->isHide;
  324.     }
  325.     public function setIsHide($value)
  326.     {
  327.         $this->isHide $value;
  328.         return $this;
  329.     }
  330.     public function getCreatedAt()
  331.     {
  332.         return $this->createdAt;
  333.     }
  334.     public function getUpdatedAt()
  335.     {
  336.         return $this->updatedAt;
  337.     }
  338. }