src/Containers/OscpvSection/CalculationContainer/Entities/CalculationEntity.php line 107

Open in your IDE?
  1. <?php
  2. namespace App\Containers\OscpvSection\CalculationContainer\Entities;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Get;
  5. use ApiPlatform\Metadata\Delete;
  6. use ApiPlatform\Metadata\GetCollection;
  7. use ApiPlatform\Metadata\Patch;
  8. use ApiPlatform\Metadata\Put;
  9. use ApiPlatform\Metadata\ApiFilter;
  10. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  11. use ApiPlatform\Doctrine\Orm\Filter\NumericFilter;
  12. use ApiPlatform\Doctrine\Orm\Filter\RangeFilter;
  13. use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
  14. use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
  15. use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  16. use Symfony\Component\Serializer\Annotation\Groups;
  17. use Symfony\Component\Serializer\Annotation\MaxDepth;
  18. use Symfony\Component\Serializer\Annotation\Context;
  19. use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
  20. use Doctrine\ORM\Mapping as ORM;
  21. use Doctrine\DBAL\Types\Types;
  22. use Gedmo\Mapping\Annotation as Gedmo;
  23. use App\Containers\OscpvSection\CalculationContainer\Data\Repositories\CalculationRepository;
  24. use App\Containers\CrmSection\ClientContainer\Entities\ClientEntity;
  25. use App\Containers\CrmSection\CarContainer\Entities\CarEntity;
  26. use App\Containers\SettingSection\ListContainer\Entities\SourceEntity;
  27. use App\Containers\SettingSection\ListContainer\Entities\StatusEntity;
  28. use App\Containers\OscpvSection\ListContainer\Entities\CarTypeEntity;
  29. use App\Containers\SettingSection\ListContainer\Entities\CarBrandEntity;
  30. use App\Containers\SettingSection\ListContainer\Entities\CarModelEntity;
  31. use App\Containers\OscpvSection\ListContainer\Entities\CityEntity;
  32. use App\Containers\OscpvSection\ListContainer\Entities\PrivilegeEntity;
  33. use App\Containers\OscpvSection\ListContainer\Entities\FranchiseEntity;
  34. use App\Containers\OscpvSection\ListContainer\Entities\VoluntaryInsuranceEntity;
  35. use App\Containers\OscpvSection\IndexContainer\Entities\TranslationEntity;
  36. use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
  37. /** 
  38.  * Расчет
  39. */
  40. #[ApiResource(
  41.     routePrefix'/oscpv',
  42.     normalizationContext: [
  43.         'groups' => 'read',
  44.         'enable_max_depth' => true
  45.     ],
  46.     operations: [
  47.         new Get(
  48.             uriTemplate'/calculations/{id}'requirements: ['id' => '\d+'],
  49.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  50.         ),
  51.         new Patch(
  52.             uriTemplate'/calculations/{id}'requirements: ['id' => '\d+'],
  53.             security"is_granted('ROLE_ADMIN')"
  54.         ),
  55.         // new Put(
  56.         //     uriTemplate: '/calculations/{id}', requirements: ['id' => '\d+'],
  57.         //     security: "is_granted('ROLE_ADMIN')"
  58.         // ),
  59.         new Delete(
  60.             uriTemplate'/calculations/{id}'requirements: ['id' => '\d+'],
  61.             security"is_granted('ROLE_ADMIN')"
  62.         ),
  63.         new GetCollection(
  64.             uriTemplate'/calculations',
  65.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
  66.         ),
  67.     ],
  68.     shortName'OSCPV_Calculations'
  69. )]
  70. #[ApiFilter(SearchFilter::class, properties: [
  71.     'id' => 'exact'
  72.     'carNumber' => 'partial',
  73.     'promoCode' => 'partial',
  74.     'dateProduction' => 'exact'
  75.     'externalCode' => 'exact'
  76.     'carType' => 'exact',
  77.     'client' => 'exact',
  78.     'carBrand' => 'exact',
  79.     'carModel' => 'exact',
  80.     'source' => 'exact',
  81.     'car' => 'exact',
  82.     'client.name' => 'partial'
  83.     'client.lastName' => 'partial'
  84.     'client.patronymic' => 'partial'
  85.     'client.externalCode' => 'partial'
  86.     'status' => 'exact',
  87.     'status.name' => 'partial'
  88.     'status.externalCode' => 'partial'
  89.     'carBrand.name' => 'exact'
  90.     'carModel.name' => 'exact'
  91. ])]
  92. #[ApiFilter(NumericFilter::class, properties: ['id'])]
  93. #[ApiFilter(RangeFilter::class, properties: ['id'])]
  94. #[ApiFilter(BooleanFilter::class, properties: ['isTaxi'])]
  95. #[ApiFilter(DateFilter::class, properties: ['createdAt''updatedAt'])]
  96. #[ApiFilter(OrderFilter::class)]
  97. #[ApiFilter(filterClassSimpleSearchFilter::class, properties: [
  98.     'externalCode''carNumber''carVIN''promoCode'
  99. ])]
  100. #[ORM\Entity(repositoryClassCalculationRepository::class)]
  101. #[ORM\Table(name'`oscpv_calculations`')]
  102. #[ORM\Index(columns: ['car_number'], name'oscpv_calculations_custom_idx')]
  103. #[Gedmo\TranslationEntity(class: TranslationEntity::class)]
  104. class CalculationEntity
  105. {   
  106.     #[ORM\Id]
  107.     #[ORM\GeneratedValue]
  108.     #[ORM\Column(typeTypes::INTEGER)]
  109.     #[Groups(['read'])]
  110.     private ?int $id null;
  111.     #[ORM\Column(typeTypes::STRINGlength255nullabletrueuniquetrue)]
  112.     #[Groups(['read'])]
  113.     private ?string $externalCode null;
  114.     // Клиент
  115.     #[ORM\ManyToOne(targetEntityClientEntity::class)]
  116.     #[ORM\JoinColumn(name'client_id'referencedColumnName'id'nullabletrue)]
  117.     #[Groups(['read'])]
  118.     #[MaxDepth(2)]
  119.     private ?ClientEntity $client null;
  120.     // Статус
  121.     #[ORM\ManyToOne(targetEntityStatusEntity::class)]
  122.     #[ORM\JoinColumn(name'status_id'referencedColumnName'id'nullabletrue)]
  123.     #[Groups(['read'])]
  124.     #[MaxDepth(1)]
  125.     private ?StatusEntity $status null;
  126.     // Автомобиль
  127.     #[ORM\ManyToOne(targetEntityCarEntity::class)]
  128.     #[ORM\JoinColumn(name'car_id'referencedColumnName'id'nullablefalse)]
  129.     #[Groups(['read'])]
  130.     #[MaxDepth(2)]
  131.     private CarEntity $car;
  132.     // Номер авто
  133.     #[ORM\Column(typeTypes::STRINGlength50nullablefalse)]
  134.     #[Groups(['read'])]
  135.     private string $carNumber;
  136.     // Марка
  137.     #[ORM\ManyToOne(targetEntityCarBrandEntity::class)]
  138.     #[ORM\JoinColumn(name'car_brand_id'referencedColumnName'id'nullablefalse)]
  139.     #[Groups(['read'])]
  140.     #[MaxDepth(1)]
  141.     private CarBrandEntity $carBrand;
  142.     // Модель
  143.     #[ORM\ManyToOne(targetEntityCarModelEntity::class)]
  144.     #[ORM\JoinColumn(name'car_model_id'referencedColumnName'id'nullablefalse)]
  145.     #[Groups(['read'])]
  146.     #[MaxDepth(1)]
  147.     private CarModelEntity $carModel;
  148.     // Год выпуска
  149.     #[ORM\Column(typeTypes::INTEGERlength4nullablefalse)]
  150.     #[Groups(['read'])]
  151.     private int $dateProduction;
  152.     // Объем двигателя
  153.     #[ORM\ManyToOne(targetEntityCarTypeEntity::class)]
  154.     #[ORM\JoinColumn(name'car_type_id'referencedColumnName'id'nullablefalse)]
  155.     #[Groups(['read'])]
  156.     #[MaxDepth(1)]
  157.     private CarTypeEntity $carType;
  158.     // VIN
  159.     #[ORM\Column(typeTypes::STRINGlength150nullabletrue)]
  160.     #[Groups(['read'])]
  161.     private ?string $carVIN null;
  162.     // Город
  163.     #[ORM\ManyToOne(targetEntityCityEntity::class)]
  164.     #[ORM\JoinColumn(name'city_id'referencedColumnName'id'nullablefalse)]
  165.     #[Groups(['read'])]
  166.     #[MaxDepth(1)]
  167.     private CityEntity $city;
  168.     // Льготы
  169.     #[ORM\ManyToOne(targetEntityPrivilegeEntity::class)]
  170.     #[ORM\JoinColumn(name'privilege_id'referencedColumnName'id'nullabletrue)]
  171.     #[Groups(['read'])]
  172.     #[MaxDepth(1)]
  173.     private ?PrivilegeEntity $privilege null;
  174.     // Франшиза
  175.     #[ORM\ManyToOne(targetEntityFranchiseEntity::class)]
  176.     #[ORM\JoinColumn(name'franchise_id'referencedColumnName'id'nullabletrue)]
  177.     #[Groups(['read'])]
  178.     #[MaxDepth(1)]
  179.     private ?FranchiseEntity $franchise null;
  180.     // Используется в такси
  181.     #[ORM\Column(typeTypes::BOOLEAN)]
  182.     #[Groups(['read'])]
  183.     private ?bool $isTaxi false;
  184.     // Дополнительное добровольное страхование
  185.     #[ORM\ManyToOne(targetEntityVoluntaryInsuranceEntity::class)]
  186.     #[ORM\JoinColumn(name'voluntary_insurance_id'referencedColumnName'id'nullabletrue)]
  187.     #[Groups(['read'])]
  188.     #[MaxDepth(1)]
  189.     private ?VoluntaryInsuranceEntity $voluntaryInsurance null;
  190.     // Промокод
  191.     #[ORM\Column(typeTypes::STRINGlength150nullabletrue)]
  192.     #[Groups(['read'])]
  193.     private ?string $promoCode null;
  194.     // Стоимость в ГРН
  195.     #[ORM\Column(typeTypes::FLOATscale3nullabletrue)]
  196.     #[Groups(['read'])]
  197.     private ?float $priceUAH null;
  198.     // Стоимость добровольного страхования в ГРН
  199.     #[ORM\Column(typeTypes::FLOATscale3nullabletrue)]
  200.     #[Groups(['read'])]
  201.     private ?float $priceVoluntaryInsuranceUAH null;
  202.     // Результат расчета
  203.     #[ORM\Column(typeTypes::JSONnullabletrue)]
  204.     #[Groups(['read'])]
  205.     private ?string $calculation null;
  206.     // Серия льготного документа
  207.     #[ORM\Column(typeTypes::STRINGlength50nullabletrue)]
  208.     #[Groups(['read'])]
  209.     private ?string $documentSeries null;
  210.     // Номер льготного документа
  211.     #[ORM\Column(typeTypes::STRINGlength50nullabletrue)]
  212.     #[Groups(['read'])]
  213.     private ?string $documentId null;
  214.     // Кем выдан льготный документ
  215.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  216.     #[Gedmo\Translatable]
  217.     #[Groups(['read'])]
  218.     private ?string $documentIssuingAuthority null;
  219.     // Дата выдачи льготного документа
  220.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLEnullabletrue)]
  221.     #[Context(
  222.         normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'],
  223.         denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d']
  224.     )]
  225.     #[Groups(['read'])]
  226.     private ?\DateTimeInterface $documentIssueDate null;
  227.     // Источник
  228.     #[ORM\ManyToOne(targetEntitySourceEntity::class)]
  229.     #[ORM\JoinColumn(name'source_id'referencedColumnName'id'nullabletrue)]
  230.     #[Groups(['read'])]
  231.     #[MaxDepth(1)]
  232.     private ?SourceEntity $source null;
  233.     #[Gedmo\Timestampable(on'create')]
  234.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  235.     #[Groups(['read'])]
  236.     protected $createdAt;
  237.     #[Gedmo\Timestampable(on'update')]
  238.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  239.     #[Groups(['read'])]
  240.     protected $updatedAt;
  241.     /**
  242.      * Used locale to override Translation listener`s locale
  243.      * this is not a mapped field of entity metadata, just a simple property
  244.      */
  245.     #[Gedmo\Locale]
  246.     private $locale;
  247.     public function getId(): ?int
  248.     {
  249.         return $this->id;
  250.     }
  251.     public function getExternalCode()
  252.     {
  253.         return $this->externalCode;
  254.     }
  255.  
  256.     public function setExternalCode($code)
  257.     {
  258.         $this->externalCode $code;
  259.         return $this;
  260.     }
  261.     public function getClient()
  262.     {
  263.         return $this->client;
  264.     }
  265.     public function setClient($client)
  266.     {
  267.         $this->client $client;
  268.         return $this;
  269.     }
  270.     public function getStatus()
  271.     {
  272.         return $this->status;
  273.     }
  274.     public function setStatus($status)
  275.     {
  276.         $this->status $status;
  277.         return $this;
  278.     }
  279.     public function getCar()
  280.     {
  281.         return $this->car;
  282.     }
  283.     public function setCar($car)
  284.     {
  285.         $this->car $car;
  286.         return $this;
  287.     }
  288.     public function getCarNumber()
  289.     {
  290.         return $this->carNumber;
  291.     }
  292.     public function setCarNumber($number)
  293.     {
  294.         $this->carNumber = ($number !== null str_replace(' ',''trim($number)) : null);
  295.         return $this;
  296.     }
  297.     public function getCarBrand()
  298.     {
  299.         return $this->carBrand;
  300.     }
  301.     public function setCarBrand($brand)
  302.     {
  303.         $this->carBrand $brand;
  304.         return $this;
  305.     }
  306.  
  307.     public function getCarModel()
  308.     {
  309.         return $this->carModel;
  310.     }
  311.  
  312.     public function setCarModel($model)
  313.     {
  314.         $this->carModel $model;
  315.         return $this;
  316.     }
  317.     public function setDateProduction($year)
  318.     {
  319.         $this->dateProduction $year;
  320.         return $this;
  321.     }
  322.     public function getDateProduction()
  323.     {
  324.         return $this->dateProduction;
  325.     }
  326.     public function getCarType()
  327.     {
  328.         return $this->carType;
  329.     }
  330.     public function setCarType($type)
  331.     {
  332.         $this->carType $type;
  333.         return $this;
  334.     }
  335.     public function getCarVIN()
  336.     {
  337.         return $this->carVIN;
  338.     }
  339.  
  340.     public function setCarVIN($VIN)
  341.     {
  342.         $this->carVIN $VIN;
  343.         return $this;
  344.     }
  345.     public function getCity()
  346.     {
  347.         return $this->city;
  348.     }
  349.  
  350.     public function setCity($city)
  351.     {
  352.         $this->city $city;
  353.         return $this;
  354.     }
  355.     public function getPrivilege()
  356.     {
  357.         return $this->privilege;
  358.     }
  359.  
  360.     public function setPrivilege($value)
  361.     {
  362.         $this->privilege $value;
  363.         return $this;
  364.     }
  365.     public function getFranchise()
  366.     {
  367.         return $this->franchise;
  368.     }
  369.  
  370.     public function setFranchise($value)
  371.     {
  372.         $this->franchise $value;
  373.         return $this;
  374.     }
  375.     public function getIsTaxi()
  376.     {
  377.         return $this->isTaxi;
  378.     }
  379.  
  380.     public function setIsTaxi($value)
  381.     {
  382.         $this->isTaxi $value;
  383.         return $this;
  384.     }
  385.     public function getVoluntaryInsurance()
  386.     {
  387.         return $this->voluntaryInsurance;
  388.     }
  389.  
  390.     public function setVoluntaryInsurance($value)
  391.     {
  392.         $this->voluntaryInsurance $value;
  393.         return $this;
  394.     }
  395.     public function getPromoCode()
  396.     {
  397.         return $this->promoCode;
  398.     }
  399.  
  400.     public function setPromoCode($code)
  401.     {
  402.         $this->promoCode $code;
  403.         return $this;
  404.     }
  405.     public function getPriceUAH()
  406.     {
  407.         return $this->priceUAH;
  408.     }
  409.     public function setPriceUAH($price)
  410.     {
  411.         $this->priceUAH $price;
  412.         return $this;
  413.     }
  414.     public function getPriceVoluntaryInsuranceUAH()
  415.     {
  416.         return $this->priceVoluntaryInsuranceUAH;
  417.     }
  418.     public function setPriceVoluntaryInsuranceUAH($price)
  419.     {
  420.         $this->priceVoluntaryInsuranceUAH $price;
  421.         return $this;
  422.     }
  423.     public function getCalculation()
  424.     {
  425.         return json_decode($this->calculation ?? '[]'true);
  426.     }
  427.     public function setCalculation($data)
  428.     {
  429.         $this->calculation json_encode($data);
  430.         return $this;
  431.     }
  432.     
  433.     public function getDocumentSeries()
  434.     {
  435.         return $this->documentSeries;
  436.     }
  437.     public function setDocumentSeries($value)
  438.     {
  439.         $this->documentSeries $value;
  440.         return $this;
  441.     }
  442.     public function getDocumentId()
  443.     {
  444.         return $this->documentId;
  445.     }
  446.     public function setDocumentId($value)
  447.     {
  448.         $this->documentId $value;
  449.         return $this;
  450.     }
  451.     public function getDocumentIssuingAuthority()
  452.     {
  453.         return $this->documentIssuingAuthority;
  454.     }
  455.     public function setDocumentIssuingAuthority($value)
  456.     {
  457.         $this->documentIssuingAuthority $value;
  458.         return $this;
  459.     }
  460.     public function setDocumentIssueDate(\DateTimeImmutable|null $date)
  461.     {
  462.         $this->documentIssueDate $date;
  463.         return $this;
  464.     }
  465.     public function getDocumentIssueDate()
  466.     {
  467.         return $this->documentIssueDate;
  468.     }
  469.     public function getSource()
  470.     {
  471.         return $this->source;
  472.     }
  473.     public function setSource($source)
  474.     {
  475.         $this->source $source;
  476.         return $this;
  477.     }
  478.     public function getCreatedAt()
  479.     {
  480.         return $this->createdAt;
  481.     }
  482.     public function getUpdatedAt()
  483.     {
  484.         return $this->updatedAt;
  485.     }
  486.     public function setTranslatableLocale($locale)
  487.     {
  488.         $this->locale $locale;
  489.     }
  490. }