<?php
namespace App\Containers\CrmSection\CarContainer\Entities;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Doctrine\Orm\Filter\NumericFilter;
use ApiPlatform\Doctrine\Orm\Filter\RangeFilter;
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping\MappedSuperclass;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
use App\Containers\CrmSection\IndexContainer\Entities\TranslationEntity;
use App\Containers\CrmSection\CarContainer\Data\Repositories\CarRepository;
use App\Containers\CrmSection\ClientContainer\Entities\ClientEntity;
use App\Containers\SettingSection\ListContainer\Entities\FuelTypeEntity;
use App\Containers\SettingSection\ListContainer\Entities\CarTypeEntity;
use App\Containers\SettingSection\ListContainer\Entities\CarBrandEntity;
use App\Containers\SettingSection\ListContainer\Entities\CarModelEntity;
use App\Containers\OscpvSection\ListContainer\Entities\CarTypeEntity as OscpvCarTypeEntity;
use App\Containers\CrmSection\CarContainer\UI\ApiPlatform\Controllers\GetCarsByContractStatusesController;
/**
* Автомобиль
*/
#[ApiResource(
routePrefix: '/crm',
normalizationContext: [
'groups' => 'read',
'enable_max_depth' => true
],
operations: [
new Get(
uriTemplate: '/cars/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_INSTALLER') or is_granted('ROLE_READONLY')"
),
new Patch(
uriTemplate: '/cars/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
),
// new Put(
// uriTemplate: '/cars/{id}', requirements: ['id' => '\d+'],
// security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
// ),
// new Delete(
// uriTemplate: '/cars/{id}', requirements: ['id' => '\d+'],
// security: "is_granted('ROLE_ADMIN')"
// ),
// new Post(
// uriTemplate: '/cars',
// security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
// ),
new GetCollection(
uriTemplate: '/cars',
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_INSTALLER') or is_granted('ROLE_READONLY')"
),
new GetCollection(
uriTemplate: '/cars/by_contracts',
controller: GetCarsByContractStatusesController::class,
openapiContext: [
"summary" => "",
"description" => "",
'parameters' => [
[
'in' => 'query',
'name' => 'contract.status.id',
'required' => false,
'schema' => [
'type' => 'array'
]
]
]
],
security: "is_granted('ROLE_USER_CLIENT')"
)
],
shortName: 'CRM_Cars'
)]
#[ApiFilter(SearchFilter::class, properties: [
'id' => 'exact',
'externalCode' => 'partial',
'name' => 'partial',
'carNumber' => 'partial',
'carVIN' => 'partial',
'carColor' => 'exact',
'client' => 'exact',
'carFuelType' => 'exact',
'carType' => 'exact',
'carBrand' => 'exact',
'carModel' => 'exact',
'client.name' => 'partial',
'client.lastName' => 'partial',
'client.patronymic' => 'partial',
'client.externalCode' => 'partial',
'client.phone' => 'exact',
'client.email' => 'exact',
'client.inn' => 'exact',
'carBrand.name' => 'exact',
'carBrand.codeAutoria' => 'exact',
'carModel.name' => 'exact',
'carModel.codeAutoria' => 'exact',
'oscpvCarType' => 'exact',
'oscpvCityCode' => 'exact',
'oscpvZoneCode' => 'exact',
])]
#[ApiFilter(NumericFilter::class, properties: ['id', 'sorting', 'dateProduction'])]
#[ApiFilter(RangeFilter::class, properties: ['id', 'sorting', 'dateProduction', 'carEngineVolume'])]
#[ApiFilter(BooleanFilter::class, properties: ['isActive', 'oscpvIsStolen'])]
#[ApiFilter(OrderFilter::class)]
#[ApiFilter(filterClass: SimpleSearchFilter::class, properties: [
'name', 'externalCode', 'carVIN'
])]
#[ORM\Entity(repositoryClass: CarRepository::class)]
#[ORM\Table(name: '`crm_cars`')]
#[ORM\Index(columns: ['name', 'car_number'], name: 'crm_cars_custom_idx')]
#[Gedmo\TranslationEntity(class: TranslationEntity::class)]
#[MappedSuperclass]
class CarEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
#[Groups(['read'])]
private ?int $id = null;
#[ORM\Column(type: Types::STRING, length: 255, nullable: true, unique: true)]
#[Groups(['read'])]
private ?string $externalCode = null;
// Название
#[ORM\Column(type: Types::STRING, length: 50, nullable: true)]
#[Gedmo\Translatable]
#[Groups(['read'])]
private ?string $name = null;
// Сортування
#[ORM\Column(type: Types::INTEGER, length: 10, options: ['default' => 500])]
#[Groups(['read'])]
private ?int $sorting = 500;
// Клиент
#[ORM\ManyToOne(targetEntity: ClientEntity::class)]
#[ORM\JoinColumn(name: 'client_id', referencedColumnName: 'id', nullable: false)]
#[Groups(['read'])]
#[MaxDepth(2)]
private ClientEntity $client;
// Активность
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => true])]
#[Groups(['read'])]
private bool $isActive = true;
// Номер авто
#[ORM\Column(type: Types::STRING, length: 50, nullable: false)]
#[Groups(['read'])]
private string $carNumber;
// Год выпуска
#[ORM\Column(type: Types::INTEGER, length: 4, nullable: true)]
#[Groups(['read'])]
private ?int $dateProduction = null;
// Объем двигателя
#[ORM\Column(type: Types::FLOAT, scale: 3, nullable: true)]
#[Groups(['read'])]
private ?float $carEngineVolume = null;
// Маса власна
#[ORM\Column(type: Types::FLOAT, scale: 3, nullable: true)]
#[Groups(['read'])]
private ?float $weight = null;
// Маса повна
#[ORM\Column(type: Types::FLOAT, scale: 3, nullable: true)]
#[Groups(['read'])]
private ?float $weightTotal = null;
// К-сть місць для сидіння
#[ORM\Column(type: Types::INTEGER, scale: 3, nullable: true)]
#[Groups(['read'])]
private ?int $seats = null;
// Тип топлива
#[ORM\ManyToOne(targetEntity: FuelTypeEntity::class)]
#[ORM\JoinColumn(name: 'car_fuel_type_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
#[MaxDepth(1)]
private ?FuelTypeEntity $carFuelType = null;
// Тип транспорта
#[ORM\ManyToOne(targetEntity: CarTypeEntity::class)]
#[ORM\JoinColumn(name: 'car_type_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
#[MaxDepth(1)]
private ?CarTypeEntity $carType = null;
// VIN
#[ORM\Column(type: Types::STRING, length: 150, nullable: true)]
#[Groups(['read'])]
private ?string $carVIN = null;
// Марка
#[ORM\ManyToOne(targetEntity: CarBrandEntity::class)]
#[ORM\JoinColumn(name: 'car_brand_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
#[MaxDepth(1)]
private ?CarBrandEntity $carBrand = null;
// Модель
#[ORM\ManyToOne(targetEntity: CarModelEntity::class)]
#[ORM\JoinColumn(name: 'car_model_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
#[MaxDepth(1)]
private ?CarModelEntity $carModel = null;
// Цвет
#[ORM\Column(type: Types::STRING, length: 150, nullable: true)]
#[Gedmo\Translatable]
#[Groups(['read'])]
private ?string $carColor = null;
// // Расчеты
// #[Groups(['read'])]
// public ?array $calculations = null;
// // Договора
// #[Groups(['read'])]
// public ?array $contracts = null;
// // Доп. соглашения
// #[Groups(['read'])]
// public ?array $agreements = null;
// // Оплати
// #[Groups(['read'])]
// public ?array $payments = null;
// // Страховые случаи
// #[Groups(['read'])]
// public ?array $insuranceCases = null;
// Типы автомобиля/двигателя
#[ORM\ManyToOne(targetEntity: OscpvCarTypeEntity::class)]
#[ORM\JoinColumn(name: 'oscpv_car_type_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
#[MaxDepth(1)]
private ?OscpvCarTypeEntity $oscpvCarType = null;
// Украденный
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
#[Groups(['read'])]
private bool $oscpvIsStolen = false;
// Регистрация
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
#[Groups(['read'])]
private ?string $oscpvRegistration = null;
// Регистрационный знак
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
#[Groups(['read'])]
private ?string $oscpvRegistrationLabel = null;
// Место регистрации
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
#[Groups(['read'])]
private ?string $oscpvRegistrationPlace = null;
// ДМРЕО города
#[ORM\Column(type: Types::STRING, length: 25, nullable: true)]
#[Groups(['read'])]
private ?string $oscpvCityCode = null;
// Зона
#[ORM\Column(type: Types::STRING, length: 25, nullable: true)]
#[Groups(['read'])]
private ?string $oscpvZoneCode = null;
#[Gedmo\Timestampable(on: 'create')]
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
#[Groups(['read'])]
protected $createdAt;
#[Gedmo\Timestampable(on: 'update')]
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
#[Groups(['read'])]
protected $updatedAt;
/**
* Used locale to override Translation listener`s locale
* this is not a mapped field of entity metadata, just a simple property
*/
#[Gedmo\Locale]
private $locale;
public function getId(): ?int
{
return $this->id;
}
public function getExternalCode()
{
return $this->externalCode;
}
public function setExternalCode($code)
{
$this->externalCode = $code;
return $this;
}
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
return $this;
}
public function getSorting()
{
return $this->sorting;
}
public function setSorting($sorting)
{
$this->sorting = $sorting;
return $this;
}
public function getClient()
{
return $this->client;
}
public function setClient($client)
{
$this->client = $client;
return $this;
}
public function getIsActive()
{
return $this->isActive;
}
public function setIsActive($isActive)
{
$this->isActive = $isActive;
return $this;
}
public function getCarNumber()
{
return $this->carNumber;
}
public function setCarNumber($number)
{
$this->carNumber = ($number !== null ? str_replace(' ','', trim($number)) : null);
return $this;
}
public function setDateProduction($year)
{
$this->dateProduction = $year;
return $this;
}
public function getDateProduction()
{
return $this->dateProduction;
}
public function getCarBrand()
{
return $this->carBrand;
}
public function setCarBrand($brand)
{
$this->carBrand = $brand;
return $this;
}
public function getCarModel()
{
return $this->carModel;
}
public function setCarModel($model)
{
$this->carModel = $model;
return $this;
}
public function getCarColor()
{
return $this->carColor;
}
public function setCarColor($color)
{
$this->carColor = $color;
return $this;
}
public function getCarEngineVolume()
{
return $this->carEngineVolume;
}
public function setCarEngineVolume($value)
{
$this->carEngineVolume = ($value !== null ? round($value, 3) : null);
return $this;
}
public function getWeight()
{
return $this->weight;
}
public function setWeight($value)
{
$this->weight = $value ? round($value, 3) : null;
return $this;
}
public function getWeightTotal()
{
return $this->weightTotal;
}
public function setWeightTotal($value)
{
$this->weightTotal = $value ? round($value, 3) : null;
return $this;
}
public function getSeats()
{
return $this->seats;
}
public function setSeats($value)
{
$this->seats = $value;
return $this;
}
public function getCarFuelType()
{
return $this->carFuelType;
}
public function setCarFuelType($type)
{
$this->carFuelType = $type;
return $this;
}
public function getCarType()
{
return $this->carType;
}
public function setCarType($type)
{
$this->carType = $type;
return $this;
}
public function getCarVIN()
{
return $this->carVIN;
}
public function setCarVIN($VIN)
{
$this->carVIN = $VIN;
return $this;
}
public function getOscpvCarType()
{
return $this->oscpvCarType;
}
public function setOscpvCarType($type)
{
$this->oscpvCarType = $type;
return $this;
}
public function getOscpvIsStolen()
{
return $this->oscpvIsStolen;
}
public function setOscpvIsStolen($isStolen)
{
$this->oscpvIsStolen = $isStolen;
return $this;
}
public function getOscpvRegistration()
{
return $this->oscpvRegistration;
}
public function setOscpvRegistration($value)
{
$this->oscpvRegistration = $value;
return $this;
}
public function getOscpvRegistrationLabel()
{
return $this->oscpvRegistrationLabel;
}
public function setOscpvRegistrationLabel($value)
{
$this->oscpvRegistrationLabel = $value;
return $this;
}
public function getOscpvRegistrationPlace()
{
return $this->oscpvRegistrationPlace;
}
public function setOscpvRegistrationPlace($value)
{
$this->oscpvRegistrationPlace = $value;
return $this;
}
public function getOscpvCityCode()
{
return $this->oscpvCityCode;
}
public function setOscpvCityCode($value)
{
$this->oscpvCityCode = $value;
return $this;
}
public function getOscpvZoneCode()
{
return $this->oscpvZoneCode;
}
public function setOscpvZoneCode($value)
{
$this->oscpvZoneCode = $value;
return $this;
}
public function getCreatedAt()
{
return $this->createdAt;
}
public function getUpdatedAt()
{
return $this->updatedAt;
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
}