<?php
namespace App\Containers\ServiceSection\TravelContainer\Entities;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
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\OrderFilter;
use App\Containers\CrmSection\ContractContainer\Entities\ContractEntity;
use App\Containers\ServiceSection\TravelContainer\Data\Repositories\ContractRatingMonthRepository;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\DBAL\Types\Types;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Context;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
#[ApiResource(
shortName: 'Contract_Rating_Month',
operations: [
new Get(
uriTemplate: '/contract_rating_month/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
),
new Patch(
uriTemplate: '/contract_rating_month/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN')"
),
new Delete(
uriTemplate: '/contract_rating_month/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN')"
),
new GetCollection(
uriTemplate: '/contract_rating_month',
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
),
],
routePrefix: '/service',
normalizationContext: [
'groups' => ['contract_rating_month:read', 'read'],
'enable_max_depth' => true
],
denormalizationContext: [
'groups' => ['contract_rating_month:create', 'contract_rating_month:update']
]
)]
#[ORM\Entity(repositoryClass: ContractRatingMonthRepository::class)]
#[ORM\Table(name: '`service_contract_rating_month`')]
#[ApiFilter(SearchFilter::class, properties: [
'id' => 'exact',
'contract' => 'exact'
])]
#[ApiFilter(NumericFilter::class, properties: ['id', 'bonuses', 'rating'])]
#[ApiFilter(RangeFilter::class, properties: ['id', 'bonuses', 'mileage'])]
#[ApiFilter(DateFilter::class, properties: ['date', 'createdAt', 'updatedAt'])]
#[ApiFilter(OrderFilter::class)]
class ContractRatingMonthEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
#[Groups(['contract_rating_month:read'])]
private ?int $id = null;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: false)]
#[Context(
normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'],
denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']
)]
#[Groups(['contract_rating_month:read'])]
private \DateTimeInterface $date;
#[ORM\ManyToOne(targetEntity: ContractEntity::class)]
#[ORM\JoinColumn(name: 'contract_id', referencedColumnName: 'id', nullable: false)]
#[Groups(['contract_rating_month:read'])]
#[MaxDepth(1)]
private ContractEntity $contract;
#[ORM\Column(type: Types::FLOAT, scale: 2, options: ['default' => 0.00])]
#[Groups(['contract_rating_month:read'])]
private ?float $rating = 0.00;
#[ORM\Column(type: Types::FLOAT, scale: 2, options: ['default' => 0.00])]
#[Groups(['contract_rating_month:read'])]
private ?float $mileage = 0.00;
#[ORM\Column(type: Types::INTEGER, length: 10, options: ['default' => 0])]
#[Groups(['contract_rating_month:read'])]
private ?int $bonuses = 0;
#[Gedmo\Timestampable(on: 'create')]
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
#[Groups(['contract_rating_month:read'])]
protected \DateTimeInterface $createdAt;
#[Gedmo\Timestampable(on: 'update')]
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
#[Groups(['contract_rating_month:read'])]
protected \DateTimeInterface $updatedAt;
public function getId(): ?int
{
return $this->id;
}
public function getDate(): ?\DateTimeInterface
{
return $this->date;
}
public function setDate(\DateTimeImmutable $date): ?self
{
$this->date = $date;
return $this;
}
public function getContract(): ?ContractEntity
{
return $this->contract;
}
public function setContract($contract): ?self
{
$this->contract = $contract;
return $this;
}
public function getRating(): ?float
{
return $this->rating;
}
public function setRating(?float $value): ?self
{
$this->rating = $value ? round($value, 2) : 0.00;
return $this;
}
public function getMileage(): ?float
{
return $this->mileage;
}
public function setMileage(?float $value): ?self
{
$this->mileage = $value ? round($value, 2) : 0.00;
return $this;
}
public function getBonuses(): int
{
return $this->bonuses;
}
public function setBonuses(?int $bonuses): ?self
{
$this->bonuses = $bonuses;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
}