src/Containers/CrmSection/CarContainer/Entities/CarEntity.php line 131

Open in your IDE?
  1. <?php
  2. namespace App\Containers\CrmSection\CarContainer\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 Doctrine\ORM\Mapping\MappedSuperclass;
  20. use Gedmo\Mapping\Annotation as Gedmo;
  21. use Symfony\Component\Serializer\Annotation\Groups;
  22. use Symfony\Component\Serializer\Annotation\MaxDepth;
  23. use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
  24. use App\Containers\CrmSection\IndexContainer\Entities\TranslationEntity;
  25. use App\Containers\CrmSection\CarContainer\Data\Repositories\CarRepository;
  26. use App\Containers\CrmSection\ClientContainer\Entities\ClientEntity;
  27. use App\Containers\SettingSection\ListContainer\Entities\FuelTypeEntity;
  28. use App\Containers\SettingSection\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\CarTypeEntity as OscpvCarTypeEntity;
  32. use App\Containers\CrmSection\CarContainer\UI\ApiPlatform\Controllers\GetCarsByContractStatusesController;
  33. /** 
  34.  * Автомобиль
  35. */
  36. #[ApiResource(
  37.     routePrefix'/crm',
  38.     normalizationContext: [
  39.         'groups' => 'read',
  40.         'enable_max_depth' => true
  41.     ],
  42.     operations: [
  43.         new Get(
  44.             uriTemplate'/cars/{id}'requirements: ['id' => '\d+'],
  45.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_INSTALLER') or is_granted('ROLE_READONLY')"
  46.         ),
  47.         new Patch(
  48.             uriTemplate'/cars/{id}'requirements: ['id' => '\d+'],
  49.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  50.         ),
  51.         // new Put(
  52.         //     uriTemplate: '/cars/{id}', requirements: ['id' => '\d+'],
  53.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  54.         // ),
  55.         // new Delete(
  56.         //     uriTemplate: '/cars/{id}', requirements: ['id' => '\d+'],
  57.         //     security: "is_granted('ROLE_ADMIN')"
  58.         // ),
  59.         // new Post(
  60.         //     uriTemplate: '/cars',
  61.         //     security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
  62.         // ),
  63.         new GetCollection(
  64.             uriTemplate'/cars',
  65.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_INSTALLER') or is_granted('ROLE_READONLY')"
  66.         ),
  67.         new GetCollection(
  68.             uriTemplate'/cars/by_contracts',
  69.             controllerGetCarsByContractStatusesController::class,
  70.             openapiContext: [
  71.                 "summary" => "",
  72.                 "description" => "",
  73.                 'parameters' => [
  74.                     [
  75.                         'in' => 'query',
  76.                         'name' => 'contract.status.id',
  77.                         'required' => false,
  78.                         'schema' => [
  79.                             'type' => 'array'
  80.                         ]
  81.                     ]
  82.                 ]
  83.             ],
  84.             security"is_granted('ROLE_USER_CLIENT')"
  85.         )
  86.     ],
  87.     shortName'CRM_Cars'
  88. )]
  89. #[ApiFilter(SearchFilter::class, properties: [
  90.     'id' => 'exact'
  91.     'externalCode' => 'partial',
  92.     'name' => 'partial'
  93.     'carNumber' => 'partial'
  94.     'carVIN' => 'partial'
  95.     'carColor' => 'exact'
  96.     'client' => 'exact',
  97.     'carFuelType' => 'exact',
  98.     'carType' => 'exact',
  99.     'carBrand' => 'exact',
  100.     'carModel' => 'exact',
  101.     'client.name' => 'partial'
  102.     'client.lastName' => 'partial'
  103.     'client.patronymic' => 'partial'
  104.     'client.externalCode' => 'partial'
  105.     'client.phone' => 'exact'
  106.     'client.email' => 'exact'
  107.     'client.inn' => 'exact'
  108.     'carBrand.name' => 'exact'
  109.     'carBrand.codeAutoria' => 'exact'
  110.     'carModel.name' => 'exact'
  111.     'carModel.codeAutoria' => 'exact',
  112.     'oscpvCarType' => 'exact',
  113.     'oscpvCityCode' => 'exact',
  114.     'oscpvZoneCode' => 'exact',
  115. ])]
  116. #[ApiFilter(NumericFilter::class, properties: ['id''sorting''dateProduction'])]
  117. #[ApiFilter(RangeFilter::class, properties: ['id''sorting''dateProduction''carEngineVolume'])]
  118. #[ApiFilter(BooleanFilter::class, properties: ['isActive''oscpvIsStolen'])]
  119. #[ApiFilter(OrderFilter::class)]
  120. #[ApiFilter(filterClassSimpleSearchFilter::class, properties: [
  121.     'name''externalCode''carVIN'
  122. ])]
  123. #[ORM\Entity(repositoryClassCarRepository::class)]
  124. #[ORM\Table(name'`crm_cars`')]
  125. #[ORM\Index(columns: ['name''car_number'], name'crm_cars_custom_idx')]
  126. #[Gedmo\TranslationEntity(class: TranslationEntity::class)]
  127. #[MappedSuperclass]
  128. class CarEntity
  129. {   
  130.     #[ORM\Id]
  131.     #[ORM\GeneratedValue]
  132.     #[ORM\Column(typeTypes::INTEGER)]
  133.     #[Groups(['read'])]
  134.     private ?int $id null;
  135.     #[ORM\Column(typeTypes::STRINGlength255nullabletrueuniquetrue)]
  136.     #[Groups(['read'])]
  137.     private ?string $externalCode null;
  138.     // Название
  139.     #[ORM\Column(typeTypes::STRINGlength50nullabletrue)]
  140.     #[Gedmo\Translatable]
  141.     #[Groups(['read'])]
  142.     private ?string $name null;
  143.     // Сортування
  144.     #[ORM\Column(typeTypes::INTEGERlength10options: ['default' => 500])]
  145.     #[Groups(['read'])]
  146.     private ?int $sorting 500;
  147.     // Клиент
  148.     #[ORM\ManyToOne(targetEntityClientEntity::class)]
  149.     #[ORM\JoinColumn(name'client_id'referencedColumnName'id'nullablefalse)]
  150.     #[Groups(['read'])]
  151.     #[MaxDepth(2)]
  152.     private ClientEntity $client;
  153.     // Активность
  154.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => true])]
  155.     #[Groups(['read'])]
  156.     private bool $isActive true;
  157.     // Номер авто
  158.     #[ORM\Column(typeTypes::STRINGlength50nullablefalse)]
  159.     #[Groups(['read'])]
  160.     private string $carNumber;
  161.     // Год выпуска
  162.     #[ORM\Column(typeTypes::INTEGERlength4nullabletrue)]
  163.     #[Groups(['read'])]
  164.     private ?int $dateProduction null;
  165.     // Объем двигателя
  166.     #[ORM\Column(typeTypes::FLOATscale3nullabletrue)]
  167.     #[Groups(['read'])]
  168.     private ?float $carEngineVolume null;
  169.     // Маса власна
  170.     #[ORM\Column(typeTypes::FLOATscale3nullabletrue)]
  171.     #[Groups(['read'])]
  172.     private ?float $weight null;
  173.     // Маса повна
  174.     #[ORM\Column(typeTypes::FLOATscale3nullabletrue)]
  175.     #[Groups(['read'])]
  176.     private ?float $weightTotal null;
  177.     // К-сть місць для сидіння
  178.     #[ORM\Column(typeTypes::INTEGERscale3nullabletrue)]
  179.     #[Groups(['read'])]
  180.     private ?int $seats null;
  181.     // Тип топлива
  182.     #[ORM\ManyToOne(targetEntityFuelTypeEntity::class)]
  183.     #[ORM\JoinColumn(name'car_fuel_type_id'referencedColumnName'id'nullabletrue)]
  184.     #[Groups(['read'])]
  185.     #[MaxDepth(1)]
  186.     private ?FuelTypeEntity $carFuelType null;
  187.     // Тип транспорта
  188.     #[ORM\ManyToOne(targetEntityCarTypeEntity::class)]
  189.     #[ORM\JoinColumn(name'car_type_id'referencedColumnName'id'nullabletrue)]
  190.     #[Groups(['read'])]
  191.     #[MaxDepth(1)]
  192.     private ?CarTypeEntity $carType null;
  193.     // VIN
  194.     #[ORM\Column(typeTypes::STRINGlength150nullabletrue)]
  195.     #[Groups(['read'])]
  196.     private ?string $carVIN null;
  197.     // Марка
  198.     #[ORM\ManyToOne(targetEntityCarBrandEntity::class)]
  199.     #[ORM\JoinColumn(name'car_brand_id'referencedColumnName'id'nullabletrue)]
  200.     #[Groups(['read'])]
  201.     #[MaxDepth(1)]
  202.     private ?CarBrandEntity $carBrand null;
  203.     // Модель
  204.     #[ORM\ManyToOne(targetEntityCarModelEntity::class)]
  205.     #[ORM\JoinColumn(name'car_model_id'referencedColumnName'id'nullabletrue)]
  206.     #[Groups(['read'])]
  207.     #[MaxDepth(1)]
  208.     private ?CarModelEntity $carModel null;
  209.     // Цвет
  210.     #[ORM\Column(typeTypes::STRINGlength150nullabletrue)]
  211.     #[Gedmo\Translatable]
  212.     #[Groups(['read'])]
  213.     private ?string $carColor null;
  214.     // // Расчеты
  215.     // #[Groups(['read'])]
  216.     // public ?array $calculations = null;
  217.     // // Договора
  218.     // #[Groups(['read'])]
  219.     // public ?array $contracts = null;
  220.     // // Доп. соглашения
  221.     // #[Groups(['read'])]
  222.     // public ?array $agreements = null;
  223.     // // Оплати
  224.     // #[Groups(['read'])]
  225.     // public ?array $payments = null;
  226.     // // Страховые случаи
  227.     // #[Groups(['read'])]
  228.     // public ?array $insuranceCases = null;
  229.     // Типы автомобиля/двигателя
  230.     #[ORM\ManyToOne(targetEntityOscpvCarTypeEntity::class)]
  231.     #[ORM\JoinColumn(name'oscpv_car_type_id'referencedColumnName'id'nullabletrue)]
  232.     #[Groups(['read'])]
  233.     #[MaxDepth(1)]
  234.     private ?OscpvCarTypeEntity $oscpvCarType null;
  235.     // Украденный
  236.     #[ORM\Column(typeTypes::BOOLEANoptions: ['default' => false])]
  237.     #[Groups(['read'])]
  238.     private bool $oscpvIsStolen false;
  239.     // Регистрация
  240.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  241.     #[Groups(['read'])]
  242.     private ?string $oscpvRegistration null;
  243.     // Регистрационный знак
  244.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  245.     #[Groups(['read'])]
  246.     private ?string $oscpvRegistrationLabel null;
  247.     // Место регистрации
  248.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  249.     #[Groups(['read'])]
  250.     private ?string $oscpvRegistrationPlace null;
  251.     // ДМРЕО города
  252.     #[ORM\Column(typeTypes::STRINGlength25nullabletrue)]
  253.     #[Groups(['read'])]
  254.     private ?string $oscpvCityCode null;
  255.     // Зона
  256.     #[ORM\Column(typeTypes::STRINGlength25nullabletrue)]
  257.     #[Groups(['read'])]
  258.     private ?string $oscpvZoneCode null;
  259.     #[Gedmo\Timestampable(on'create')]
  260.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  261.     #[Groups(['read'])]
  262.     protected $createdAt;
  263.     #[Gedmo\Timestampable(on'update')]
  264.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  265.     #[Groups(['read'])]
  266.     protected $updatedAt;
  267.     /**
  268.      * Used locale to override Translation listener`s locale
  269.      * this is not a mapped field of entity metadata, just a simple property
  270.      */
  271.     #[Gedmo\Locale]
  272.     private $locale;
  273.     public function getId(): ?int
  274.     {
  275.         return $this->id;
  276.     }
  277.     public function getExternalCode()
  278.     {
  279.         return $this->externalCode;
  280.     }
  281.     public function setExternalCode($code)
  282.     {
  283.         $this->externalCode $code;
  284.         return $this;
  285.     }
  286.     public function getName()
  287.     {
  288.         return $this->name;
  289.     }
  290.     public function setName($name)
  291.     {
  292.         $this->name $name;
  293.         return $this;
  294.     }
  295.     public function getSorting()
  296.     {
  297.         return $this->sorting;
  298.     }
  299.     public function setSorting($sorting)
  300.     {
  301.         $this->sorting $sorting;
  302.         return $this;
  303.     }
  304.  
  305.     public function getClient()
  306.     {
  307.         return $this->client;
  308.     }
  309.     public function setClient($client)
  310.     {
  311.         $this->client $client;
  312.         return $this;
  313.     }
  314.     public function getIsActive()
  315.     {
  316.         return $this->isActive;
  317.     }
  318.     public function setIsActive($isActive)
  319.     {
  320.         $this->isActive $isActive;
  321.         return $this;
  322.     }
  323.     public function getCarNumber()
  324.     {
  325.         return $this->carNumber;
  326.     }
  327.     public function setCarNumber($number)
  328.     {
  329.         $this->carNumber = ($number !== null str_replace(' ',''trim($number)) : null);
  330.         return $this;
  331.     }
  332.     public function setDateProduction($year)
  333.     {
  334.         $this->dateProduction $year;
  335.         return $this;
  336.     }
  337.     public function getDateProduction()
  338.     {
  339.         return $this->dateProduction;
  340.     }
  341.     public function getCarBrand()
  342.     {
  343.         return $this->carBrand;
  344.     }
  345.     public function setCarBrand($brand)
  346.     {
  347.         $this->carBrand $brand;
  348.         return $this;
  349.     }
  350.     public function getCarModel()
  351.     {
  352.         return $this->carModel;
  353.     }
  354.     public function setCarModel($model)
  355.     {
  356.         $this->carModel $model;
  357.         return $this;
  358.     }
  359.     public function getCarColor()
  360.     {
  361.         return $this->carColor;
  362.     }
  363.     public function setCarColor($color)
  364.     {
  365.         $this->carColor $color;
  366.         return $this;
  367.     }
  368.     public function getCarEngineVolume()
  369.     {
  370.         return $this->carEngineVolume;
  371.     }
  372.     public function setCarEngineVolume($value)
  373.     {
  374.         $this->carEngineVolume = ($value !== null round($value3) : null);
  375.         return $this;
  376.     }
  377.     public function getWeight()
  378.     {
  379.         return $this->weight;
  380.     }
  381.     public function setWeight($value)
  382.     {
  383.         $this->weight $value round($value3) : null;
  384.         return $this;
  385.     }
  386.     public function getWeightTotal()
  387.     {
  388.         return $this->weightTotal;
  389.     }
  390.     public function setWeightTotal($value)
  391.     {
  392.         $this->weightTotal $value round($value3) : null;
  393.         return $this;
  394.     }
  395.     public function getSeats()
  396.     {
  397.         return $this->seats;
  398.     }
  399.     public function setSeats($value)
  400.     {
  401.         $this->seats $value;
  402.         return $this;
  403.     }
  404.     public function getCarFuelType()
  405.     {
  406.         return $this->carFuelType;
  407.     }
  408.     public function setCarFuelType($type)
  409.     {
  410.         $this->carFuelType $type;
  411.         return $this;
  412.     }
  413.     public function getCarType()
  414.     {
  415.         return $this->carType;
  416.     }
  417.     public function setCarType($type)
  418.     {
  419.         $this->carType $type;
  420.         return $this;
  421.     }
  422.     public function getCarVIN()
  423.     {
  424.         return $this->carVIN;
  425.     }
  426.     public function setCarVIN($VIN)
  427.     {
  428.         $this->carVIN $VIN;
  429.         return $this;
  430.     }
  431.     public function getOscpvCarType()
  432.     {
  433.         return $this->oscpvCarType;
  434.     }
  435.     public function setOscpvCarType($type)
  436.     {
  437.         $this->oscpvCarType $type;
  438.         return $this;
  439.     }
  440.     public function getOscpvIsStolen()
  441.     {
  442.         return $this->oscpvIsStolen;
  443.     }
  444.     public function setOscpvIsStolen($isStolen)
  445.     {
  446.         $this->oscpvIsStolen $isStolen;
  447.         return $this;
  448.     }
  449.     public function getOscpvRegistration()
  450.     {
  451.         return $this->oscpvRegistration;
  452.     }
  453.     public function setOscpvRegistration($value)
  454.     {
  455.         $this->oscpvRegistration $value;
  456.         return $this;
  457.     }
  458.     public function getOscpvRegistrationLabel()
  459.     {
  460.         return $this->oscpvRegistrationLabel;
  461.     }
  462.     public function setOscpvRegistrationLabel($value)
  463.     {
  464.         $this->oscpvRegistrationLabel $value;
  465.         return $this;
  466.     }
  467.     public function getOscpvRegistrationPlace()
  468.     {
  469.         return $this->oscpvRegistrationPlace;
  470.     }
  471.     public function setOscpvRegistrationPlace($value)
  472.     {
  473.         $this->oscpvRegistrationPlace $value;
  474.         return $this;
  475.     }
  476.     public function getOscpvCityCode()
  477.     {
  478.         return $this->oscpvCityCode;
  479.     }
  480.     public function setOscpvCityCode($value)
  481.     {
  482.         $this->oscpvCityCode $value;
  483.         return $this;
  484.     }
  485.     public function getOscpvZoneCode()
  486.     {
  487.         return $this->oscpvZoneCode;
  488.     }
  489.     public function setOscpvZoneCode($value)
  490.     {
  491.         $this->oscpvZoneCode $value;
  492.         return $this;
  493.     }
  494.     public function getCreatedAt()
  495.     {
  496.         return $this->createdAt;
  497.     }
  498.     public function getUpdatedAt()
  499.     {
  500.         return $this->updatedAt;
  501.     }
  502.     public function setTranslatableLocale($locale)
  503.     {
  504.         $this->locale $locale;
  505.     }
  506. }