<?php
namespace App\Containers\CrmSection\CalculationContainer\Entities;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Put;
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 Symfony\Component\Serializer\Annotation\Groups;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\DBAL\Types\Types;
use Gedmo\Mapping\Annotation as Gedmo;
use App\Containers\CrmSection\CalculationContainer\Data\Repositories\CalculationRepository;
use App\Containers\CrmSection\ClientContainer\Entities\ClientEntity;
use App\Containers\SettingSection\PartnerContainer\Entities\PartnerEntity;
use App\Containers\CrmSection\CarContainer\Entities\CarEntity;
use App\Containers\SettingSection\ListContainer\Entities\CarBrandEntity;
use App\Containers\SettingSection\ListContainer\Entities\CarModelEntity;
use App\Containers\SettingSection\ListContainer\Entities\SourceEntity;
use App\Containers\SettingSection\ListContainer\Entities\StatusEntity;
use App\Containers\SettingSection\ListContainer\Entities\FuelTypeEntity;
use App\Containers\SettingSection\ListContainer\Entities\CarTypeEntity;
use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
/**
* Расчет
*/
#[ApiResource(
routePrefix: '/crm',
normalizationContext: ['groups' => 'read'],
operations: [
new Get(
uriTemplate: '/calculations/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_USER_GUEST') or is_granted('ROLE_READONLY')"
),
new Patch(
uriTemplate: '/calculations/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN')"
),
// new Put(
// uriTemplate: '/calculations/{id}', requirements: ['id' => '\d+'],
// security: "is_granted('ROLE_ADMIN')"
// ),
new Delete(
uriTemplate: '/calculations/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN')"
),
new GetCollection(
uriTemplate: '/calculations',
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
),
],
shortName: 'CRM_Calculations'
)]
#[ApiFilter(SearchFilter::class, properties: [
'id' => 'exact',
'carNumber' => 'partial',
'dateProduction' => 'exact',
'externalCode' => 'exact',
'carFuelType' => 'exact',
'carType' => 'exact',
'client' => 'exact',
'email' => 'partial',
'phone' => 'partial',
'carBrand' => 'exact',
'carModel' => 'exact',
'source' => 'exact',
'car' => 'exact',
'client.name' => 'partial',
'client.lastName' => 'partial',
'client.patronymic' => 'partial',
'client.externalCode' => 'partial',
'partner' => 'exact',
'status' => 'exact',
'status.name' => 'partial',
'status.externalCode' => 'partial',
'carFuelType.name' => 'exact',
'carColor' => 'exact',
'carBrand.name' => 'exact',
'carModel.name' => 'exact'
])]
#[ApiFilter(NumericFilter::class, properties: ['id'])]
#[ApiFilter(RangeFilter::class, properties: ['id', 'carPriceUSD', 'carPriceUAH', 'carEngineVolume'])]
#[ApiFilter(BooleanFilter::class, properties: ['isOwnPrice', 'isMailSent'])]
#[ApiFilter(DateFilter::class, properties: ['createdAt', 'updatedAt'])]
#[ApiFilter(OrderFilter::class)]
#[ApiFilter(filterClass: SimpleSearchFilter::class, properties: [
'externalCode', 'carNumber', 'carVIN', 'carNumber', 'email', 'phone',
])]
#[ORM\Entity(repositoryClass: CalculationRepository::class)]
#[ORM\Table(name: '`crm_calculations`')]
#[ORM\Index(columns: ['car_number'], name: 'crm_calculations_custom_idx')]
class CalculationEntity
{
#[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: ClientEntity::class)]
#[ORM\JoinColumn(name: 'client_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
private ?ClientEntity $client = null;
// Партнер
#[ORM\ManyToOne(targetEntity: PartnerEntity::class)]
#[ORM\JoinColumn(name: 'partner_id', referencedColumnName: 'id', onDelete: 'SET NULL')]
#[Groups(['read'])]
private ?PartnerEntity $partner;
// Почта
#[ORM\Column(type: Types::STRING, length: 150, nullable: true)]
#[Groups(['read'])]
private ?string $email = null;
#[ORM\Column(type: Types::STRING, length: 50, nullable: true)]
#[Groups(['read'])]
private ?string $phone = null;
// Статус
#[ORM\ManyToOne(targetEntity: StatusEntity::class)]
#[ORM\JoinColumn(name: 'status_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
private ?StatusEntity $status = null;
// Номер авто
#[ORM\Column(type: Types::STRING, length: 50, nullable: false)]
#[Groups(['read'])]
private string $carNumber;
// Год выпуска
#[ORM\Column(type: Types::INTEGER, length: 4, nullable: false)]
#[Groups(['read'])]
private int $dateProduction;
// Стоимость авто в USD
#[ORM\Column(type: Types::INTEGER, nullable: false)]
#[Groups(['read'])]
private int $carPriceUSD;
// Стоимость авто в ГРН
#[ORM\Column(type: Types::INTEGER, nullable: true)]
#[Groups(['read'])]
private ?int $carPriceUAH = null;
// Объем двигателя
#[ORM\Column(type: Types::FLOAT, scale: 3, nullable: true)]
#[Groups(['read'])]
private ?float $carEngineVolume = null;
// Тип топлива
#[ORM\ManyToOne(targetEntity: FuelTypeEntity::class)]
#[ORM\JoinColumn(name: 'car_fuel_type_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
private ?FuelTypeEntity $carFuelType = null;
// Тип транспорта
#[ORM\ManyToOne(targetEntity: CarTypeEntity::class)]
#[ORM\JoinColumn(name: 'car_type_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
private ?CarTypeEntity $carType = null;
// Цвет
#[ORM\Column(type: Types::STRING, length: 150, nullable: true)]
#[Groups(['read'])]
private ?string $carColor = 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'])]
private ?CarBrandEntity $carBrand = null;
// Модель
#[ORM\ManyToOne(targetEntity: CarModelEntity::class)]
#[ORM\JoinColumn(name: 'car_model_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
private ?CarModelEntity $carModel = null;
// Cобственная цена
#[ORM\Column(type: Types::BOOLEAN)]
#[Groups(['read'])]
private ?bool $isOwnPrice = false;
#[ORM\Column(type: Types::BOOLEAN)]
#[Groups(['read'])]
private bool $isMailSent = false;
// Источник
#[ORM\ManyToOne(targetEntity: SourceEntity::class)]
#[ORM\JoinColumn(name: 'source_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
private ?SourceEntity $source = null;
// Автомобиль
#[ORM\ManyToOne(targetEntity: CarEntity::class)]
#[ORM\JoinColumn(name: 'car_id', referencedColumnName: 'id', nullable: true)]
#[Groups(['read'])]
private ?CarEntity $car = 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;
public function getId(): ?int
{
return $this->id;
}
public function getExternalCode()
{
return $this->externalCode;
}
public function setExternalCode($code)
{
$this->externalCode = $code;
return $this;
}
public function getClient()
{
return $this->client;
}
public function setClient($client)
{
$this->client = $client;
return $this;
}
public function getPartner()
{
return $this->partner;
}
public function setPartner(?PartnerEntity $partner)
{
$this->partner = $partner;
return $this;
}
public function setEmail($email)
{
$this->email = $email;
return $this;
}
public function getEmail()
{
return $this->email;
}
public function setPhone($phone)
{
$this->phone = $phone;
return $this;
}
public function getPhone()
{
return $this->phone;
}
public function getStatus()
{
return $this->status;
}
public function setStatus($status)
{
$this->status = $status;
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 getCarPriceUSD()
{
return $this->carPriceUSD;
}
public function setCarPriceUSD($price)
{
$this->carPriceUSD = $price;
return $this;
}
public function getCarPriceUAH()
{
return $this->carPriceUAH;
}
public function setCarPriceUAH($price)
{
$this->carPriceUAH = $price;
return $this;
}
public function getCarEngineVolume()
{
return $this->carEngineVolume;
}
public function setCarEngineVolume($value)
{
$this->carEngineVolume = ($value !== null ? round($value, 3) : null);
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 getCarVIN()
{
return $this->carVIN;
}
public function setCarVIN($VIN)
{
$this->carVIN = $VIN;
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 getIsOwnPrice()
{
return $this->isOwnPrice;
}
public function setIsOwnPrice($value)
{
$this->isOwnPrice = $value;
return $this;
}
public function getIsMailSent()
{
return $this->isMailSent;
}
public function setIsMailSent($value)
{
$this->isMailSent = $value;
return $this;
}
public function getSource()
{
return $this->source;
}
public function setSource($source)
{
$this->source = $source;
return $this;
}
public function getCar()
{
return $this->car;
}
public function setCar($car)
{
$this->car = $car;
return $this;
}
public function getCreatedAt()
{
return $this->createdAt;
}
public function getUpdatedAt()
{
return $this->updatedAt;
}
}