<?php
namespace App\Containers\CrmSection\EquipmentContainer\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 App\Containers\CrmSection\EquipmentContainer\UI\ApiPlatform\Controllers\ApplicationReactivateMileageController;
use App\Containers\ServiceSection\TrackingContainer\Entities\MileageEntity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\DBAL\Types\Types;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use Symfony\Component\Serializer\Annotation\Context;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
use App\Containers\CrmSection\EquipmentContainer\Data\Repositories\ApplicationRepository;
use App\Containers\CrmSection\ClientContainer\Entities\ClientEntity;
use App\Containers\CrmSection\ContractContainer\Entities\ContractEntity;
use App\Containers\CrmSection\CarContainer\Entities\CarEntity;
use App\Containers\SettingSection\ListContainer\Entities\TrackingSystemEntity;
use App\Containers\SettingSection\ListContainer\Entities\CarBrandEntity;
use App\Containers\SettingSection\ListContainer\Entities\CarModelEntity;
use App\Containers\SettingSection\ListContainer\Entities\CarTypeEntity;
use App\Containers\SettingSection\ListContainer\Entities\FuelTypeEntity;
use App\Containers\SettingSection\ListContainer\Entities\StatusEntity;
use App\Containers\CrmSection\IndexContainer\Entities\TranslationEntity;
use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
/**
* Заявка
*/
#[ApiResource(
routePrefix: '/crm',
normalizationContext: [
'groups' => 'read',
'enable_max_depth' => true
],
operations: [
new Get(
uriTemplate: '/applications/{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: '/applications/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_INSTALLER')"
),
// new Put(
// uriTemplate: '/applications/{id}', requirements: ['id' => '\d+'],
// security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
// ),
new Delete(
uriTemplate: '/applications/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN')"
),
new Post(
uriTemplate: '/applications',
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
),
new Patch(
uriTemplate: '/applications/{id}/reactivate_mileage', requirements: ['id' => '\d+'],
controller: ApplicationReactivateMileageController::class,
input: false,
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_INSTALLER')"
),
new GetCollection(
uriTemplate: '/applications',
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_INSTALLER') or is_granted('ROLE_READONLY')"
),
],
shortName: 'CRM_Equipments'
)]
#[ApiFilter(SearchFilter::class, properties: [
'id' => 'exact',
'number' => 'partial',
'carNumber' => 'partial',
'externalCode' => 'partial',
'carColor' => 'exact',
'contract' => 'exact',
'trackingSystem' => 'exact',
'client' => 'exact',
'client.name' => 'partial',
'client.lastName' => 'partial',
'client.patronymic' => 'partial',
'client.externalCode' => 'partial',
'client.phone' => 'exact',
'client.email' => 'exact',
'client.inn' => 'exact',
'insuranceProduct' => 'exact',
'insuranceProduct.name' => 'partial',
'insuranceProduct.code' => 'partial',
'carBrand' => 'exact',
'carBrand.name' => 'partial',
'carBrand.codeAutoria' => 'exact',
'carModel' => 'exact',
'carModel.name' => 'partial',
'carModel.codeAutoria' => 'exact',
'status' => 'exact',
'status.name' => 'exact',
'status.externalCode' => 'exact',
'source' => 'exact',
'source.name' => 'exact',
'source.externalCode' => 'exact',
'sensorId' => 'exact'
])]
#[ApiFilter(NumericFilter::class, properties: [
'id', 'dateProduction'
])]
#[ApiFilter(RangeFilter::class, properties: [
'id', 'priceUAH', 'carPriceUSD',
'carPriceUAH', 'dateProduction',
'carEngineVolume', 'prolongationBalanceKilometers',
'currentBalanceKilometers'
])]
#[ApiFilter(BooleanFilter::class, properties: [
'isContactMe', 'isSigned',
'isActiveTracker', 'isBlockedTracker'
])]
#[ApiFilter(DateFilter::class, properties: ['dateStart', 'dateEnd', 'dateConclusionContract', 'dateSigningContract', 'dateSigningAct'])]
#[ApiFilter(OrderFilter::class)]
#[ApiFilter(filterClass: SimpleSearchFilter::class, properties: [
'externalCode', 'address', 'comment', 'sensorId'
])]
#[ORM\Entity(repositoryClass: ApplicationRepository::class)]
#[ORM\Table(name: '`crm_equipments_applications`')]
#[ORM\Index(columns: ['car_number'], name: 'crm_equipments_applications_custom_idx')]
#[Gedmo\TranslationEntity(class: TranslationEntity::class)]
class ApplicationEntity
{
public function __construct() {
$this->mileages = new ArrayCollection();
}
#[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\ManyToOne(targetEntity: StatusEntity::class)]
#[ORM\JoinColumn(name: 'status_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
#[MaxDepth(1)]
private ?StatusEntity $status = null;
// Клиент
#[ORM\ManyToOne(targetEntity: ClientEntity::class)]
#[ORM\JoinColumn(name: 'client_id', referencedColumnName: 'id', nullable: false)]
#[Groups(['read'])]
#[MaxDepth(2)]
private ClientEntity $client;
// Договор
#[ORM\ManyToOne(targetEntity: ContractEntity::class)]
#[ORM\JoinColumn(name: 'contract_id', referencedColumnName: 'id', nullable: false)]
#[Groups(['read'])]
#[MaxDepth(2)]
private ContractEntity $contract;
// Номер авто
#[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\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\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;
// Цвет
#[ORM\Column(type: Types::STRING, length: 150, nullable: true)]
#[Gedmo\Translatable]
#[Groups(['read'])]
private ?string $carColor = null;
// Автомобиль
#[ORM\ManyToOne(targetEntity: CarEntity::class)]
#[ORM\JoinColumn(name: 'car_id', referencedColumnName: 'id', nullable: true)]
#[MaxDepth(2)]
#[Groups(['read'])]
private ?CarEntity $car = null;
// Адрес
#[ORM\Column(type: Types::STRING, length: 500, nullable: true)]
#[Groups(['read'])]
private ?string $address = null;
// Дата
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
#[Context(
normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'],
denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
)]
#[Groups(['read'])]
private ?\DateTimeInterface $date = null;
// ID датчика
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
#[Groups(['read'])]
private ?string $sensorId = null;
// Дата установки датчика
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
#[Context(
normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'],
denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
)]
#[Groups(['read'])]
private ?\DateTimeInterface $sensorInstallationDate = null;
// Дата осмотра
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
#[Context(
normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'],
denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
)]
#[Groups(['read'])]
private ?\DateTimeInterface $reviewDate = null;
// Исполнитель
#[ORM\Column(type: Types::STRING, length: 150, nullable: true)]
#[Groups(['read'])]
private ?string $executor = null;
// Показатели спидометра
#[ORM\Column(type: Types::INTEGER, nullable: true)]
#[Groups(['read'])]
private ?int $speedometer = null;
// Свидетельства о регистрации
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
#[Groups(['read'])]
private ?string $registrationCertificates = null;
// Номер шасси/кузова
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
#[Groups(['read'])]
private ?string $bodyNumber = null;
// Связаться со мной
#[ORM\Column(type: Types::BOOLEAN)]
#[Groups(['read'])]
private ?bool $isContactMe = false;
// Подписан
#[ORM\Column(type: Types::BOOLEAN)]
#[Groups(['read'])]
private ?bool $isSigned = false;
// Количество ключей
#[ORM\Column(type: Types::INTEGER, nullable: true)]
#[Groups(['read'])]
private ?int $numberKeys = null;
// Количество дубликатов ключей
#[ORM\Column(type: Types::INTEGER, nullable: true)]
#[Groups(['read'])]
private ?int $numberDuplicateKeys = null;
// Трекер активен
#[ORM\Column(type: Types::BOOLEAN)]
#[Groups(['read'])]
private ?bool $isActiveTracker = false;
// Трекер заблокирован
#[ORM\Column(type: Types::BOOLEAN)]
#[Groups(['read'])]
private ?bool $isBlockedTracker = false;
// Трекинг система
#[ORM\ManyToOne(targetEntity: TrackingSystemEntity::class)]
#[ORM\JoinColumn(name: 'tracking_system_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
#[MaxDepth(1)]
private ?TrackingSystemEntity $trackingSystem = null;
// Дата деактивации счетчика
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
#[Context(
normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'],
denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
)]
#[Groups(['read'])]
private ?\DateTimeInterface $counterDeactivationDate = null;
// Комментарий
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
#[Groups(['read'])]
private ?string $comment = null;
// Повреждения
#[Groups(['read'])]
public ?array $damages = null;
// Фото
#[Groups(['read'])]
public ?array $photos = null;
// Трекінг система для імпорту пробігу
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
#[Groups(['read'])]
private ?string $mileageTrackingSystem = null;
// Ідентифікатор пристрою Antenor
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
#[Groups(['read'])]
private ?string $antenorDeviceId = null;
#[ORM\JoinColumn(nullable: true)]
#[ORM\OneToMany(mappedBy: 'application', targetEntity: MileageEntity::class)]
#[Groups(['read'])]
private Collection $mileages;
#[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 setId($value)
{
$this->id = $value;
return $this;
}
public function getExternalCode()
{
return $this->externalCode;
}
public function setExternalCode($code)
{
$this->externalCode = $code;
return $this;
}
public function getStatus()
{
return $this->status;
}
public function setStatus($status)
{
$this->status = $status;
return $this;
}
public function getClient()
{
return $this->client;
}
public function setClient($client)
{
$this->client = $client;
return $this;
}
public function getContract()
{
return $this->contract;
}
public function setContract($contract)
{
$this->contract = $contract;
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 getCarEngineVolume()
{
return $this->carEngineVolume;
}
public function setCarEngineVolume($value)
{
$this->carEngineVolume = ($value !== null ? round($value, 3) : null);
return $this;
}
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 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 getCarColor()
{
return $this->carColor;
}
public function setCarColor($color)
{
$this->carColor = $color;
return $this;
}
public function getCar()
{
return $this->car;
}
public function setCar($car)
{
$this->car = $car;
return $this;
}
public function getAddress()
{
return $this->address;
}
public function setAddress($address)
{
$this->address = $address;
return $this;
}
public function setDate(\DateTimeImmutable|null $date)
{
$this->date = $date;
return $this;
}
public function getDate()
{
return $this->date;
}
public function getSensorId()
{
return $this->sensorId;
}
public function setSensorId($sensorId)
{
$this->sensorId = $sensorId;
return $this;
}
public function setSensorInstallationDate(\DateTimeImmutable|null $date)
{
$this->sensorInstallationDate = $date;
return $this;
}
public function getSensorInstallationDate()
{
return $this->sensorInstallationDate;
}
public function setReviewDate(\DateTimeImmutable|null $date)
{
$this->reviewDate = $date;
return $this;
}
public function getReviewDate()
{
return $this->reviewDate;
}
public function getExecutor()
{
return $this->executor;
}
public function setExecutor($executor)
{
$this->executor = $executor;
return $this;
}
public function getSpeedometer()
{
return $this->speedometer;
}
public function setSpeedometer($value)
{
$this->speedometer = $value;
return $this;
}
public function getRegistrationCertificates()
{
return $this->registrationCertificates;
}
public function setRegistrationCertificates($value)
{
$this->registrationCertificates = $value;
return $this;
}
public function getBodyNumber()
{
return $this->bodyNumber;
}
public function setBodyNumber($number)
{
$this->bodyNumber = $number;
return $this;
}
public function getIsContactMe()
{
return $this->isContactMe;
}
public function setIsContactMe($value)
{
$this->isContactMe = $value;
return $this;
}
public function getNumberKeys()
{
return $this->numberKeys;
}
public function setNumberKeys($value)
{
$this->numberKeys = $value;
return $this;
}
public function getNumberDuplicateKeys()
{
return $this->numberDuplicateKeys;
}
public function setNumberDuplicateKeys($value)
{
$this->numberDuplicateKeys = $value;
return $this;
}
public function getIsActiveTracker()
{
return $this->isActiveTracker;
}
public function setIsActiveTracker($value)
{
$this->isActiveTracker = $value;
return $this;
}
public function getIsBlockedTracker()
{
return $this->isBlockedTracker;
}
public function setIsBlockedTracker($value)
{
$this->isBlockedTracker = $value;
return $this;
}
public function getTrackingSystem()
{
return $this->trackingSystem;
}
public function setTrackingSystem($value)
{
$this->trackingSystem = $value;
return $this;
}
public function setCounterDeactivationDate(\DateTimeImmutable|null $date)
{
$this->counterDeactivationDate = $date;
return $this;
}
public function getCounterDeactivationDate()
{
return $this->counterDeactivationDate;
}
public function getComment()
{
return $this->comment;
}
public function setComment($comment)
{
$this->comment = $comment;
return $this;
}
public function setCreatedAt(\DateTimeImmutable|null $date)
{
$this->createdAt = $date;
return $this;
}
public function setUpdatedAt(\DateTimeImmutable|null $date)
{
$this->updatedAt = $date;
return $this;
}
public function getIsSigned()
{
return $this->isSigned;
}
public function setIsSigned($isSigned)
{
$this->isSigned = $isSigned;
return $this;
}
public function getCreatedAt()
{
return $this->createdAt;
}
public function getUpdatedAt()
{
return $this->updatedAt;
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
public function getMileageTrackingSystem(): ?string
{
return $this->mileageTrackingSystem;
}
public function setMileageTrackingSystem(?string $mileageTrackingSystem): self
{
$this->mileageTrackingSystem = $mileageTrackingSystem;
return $this;
}
public function getAntenorDeviceId(): ?string
{
return $this->antenorDeviceId;
}
public function setAntenorDeviceId(?string $antenorDeviceId): self
{
$this->antenorDeviceId = $antenorDeviceId;
return $this;
}
public function getMileages()
{
return $this->mileages->getValues();
}
public function addMileage(MileageEntity $mileage)
{
$this->mileages[] = $mileage;
}
public function removeMileage(MileageEntity $mileage)
{
$this->mileages->removeElement($mileage);
}
}