<?php
namespace App\Containers\CrmSection\ContractContainer\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 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\ContractContainer\Data\Repositories\AgreementRepository;
use App\Containers\CrmSection\ClientContainer\Entities\ClientEntity;
use App\Containers\CrmSection\CarContainer\Entities\CarEntity;
use App\Containers\CrmSection\ContractContainer\Entities\ContractEntity;
use App\Containers\SettingSection\ListContainer\Entities\StatusEntity;
use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
/**
* Доп. соглашение
*/
#[ApiResource(
routePrefix: '/crm',
normalizationContext: [
'groups' => 'read',
'enable_max_depth' => true
],
operations: [
new Get(
uriTemplate: '/agreements/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
),
new Patch(
uriTemplate: '/agreements/{id}', requirements: ['id' => '\d+'],
security: "is_granted('ROLE_ADMIN')"
),
// new Put(
// uriTemplate: '/agreements/{id}', requirements: ['id' => '\d+'],
// security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
// ),
// new Delete(
// uriTemplate: '/agreements/{id}', requirements: ['id' => '\d+'],
// security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
// ),
// new Post(
// uriTemplate: '/agreements',
// security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT')"
// ),
new GetCollection(
uriTemplate: '/agreements',
security: "is_granted('ROLE_ADMIN') or is_granted('ROLE_USER_CLIENT') or is_granted('ROLE_READONLY')"
),
],
shortName: 'CRM_Agreements'
)]
#[ApiFilter(SearchFilter::class, properties: [
'id' => 'exact',
'number' => 'partial',
'externalCode' => 'partial',
'status' => 'exact',
'contract' => 'exact',
'car' => 'exact',
'client' => 'exact',
'client.name' => 'partial',
'client.lastName' => 'partial',
'client.patronymic' => 'partial',
'client.externalCode' => 'partial',
'client.phone' => 'exact',
'client.email' => 'exact',
'client.inn' => 'exact',
'status' => 'exact',
'status.name' => 'exact',
'status.externalCode' => 'exact'
])]
#[ApiFilter(NumericFilter::class, properties: ['id', 'paymentUAH'])]
#[ApiFilter(RangeFilter::class, properties: ['id', 'mileage'])]
#[ApiFilter(BooleanFilter::class, properties: ['isPaid', 'isAutoPayment', 'isSentTo1C'])]
#[ApiFilter(DateFilter::class, properties: ['datePayment', 'dateConclusionAgreement'])]
#[ApiFilter(OrderFilter::class)]
#[ApiFilter(filterClass: SimpleSearchFilter::class, properties: [
'number', 'externalCode'
])]
#[ORM\Entity(repositoryClass: AgreementRepository::class)]
#[ORM\Table(name: '`crm_agreements`')]
#[ORM\Index(columns: ['number'], name: 'crm_agreements_custom_idx')]
class AgreementEntity
{
#[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, unique: true)]
#[Groups(['read'])]
private ?string $number = null;
// Статус
#[ORM\ManyToOne(targetEntity: StatusEntity::class)]
#[ORM\JoinColumn(name: 'status_id', referencedColumnName: 'id', nullable: false)]
#[Groups(['read'])]
#[MaxDepth(1)]
private StatusEntity $status;
// Клиент
#[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::INTEGER, length: 10, options: ['default' => 0])]
#[Groups(['read'])]
private ?int $mileage = 0;
// Сумма платежа в ГРН
#[ORM\Column(type: Types::FLOAT, scale: 3, nullable: false)]
#[Groups(['read'])]
private float $paymentUAH;
// Дата заключения доп. соглашения
#[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 $dateConclusionAgreement = 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 $datePayment = null;
// Cоглашение оплачено
#[ORM\Column(type: Types::BOOLEAN)]
#[Groups(['read'])]
private ?bool $isPaid = false;
// Автоматическая оплата
#[ORM\Column(type: Types::BOOLEAN)]
#[Groups(['read'])]
private ?bool $isAutoPayment = false;
// Отправлен в 1С
#[ORM\Column(type: Types::BOOLEAN)]
#[Groups(['read'])]
private ?bool $isSentTo1C = false;
// Ошибка при отправке в 1С
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
#[Groups(['read'])]
private ?string $errorSentTo1C = 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::BOOLEAN)]
#[Groups(['read'])]
private ?bool $isHide = false;
#[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 getNumber()
{
return $this->number;
}
public function setNumber($number)
{
$this->number = $number;
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 getMileage()
{
return $this->mileage;
}
public function setMileage($mileage)
{
$this->mileage = $mileage;
return $this;
}
public function getPaymentUAH()
{
return $this->paymentUAH;
}
public function setPaymentUAH($value)
{
$this->paymentUAH = ($value !== null ? round($value, 3) : null);
return $this;
}
public function setDateConclusionAgreement(\DateTimeImmutable|null $date)
{
$this->dateConclusionAgreement = $date;
return $this;
}
public function getDateConclusionAgreement()
{
return $this->dateConclusionAgreement;
}
public function setDatePayment(\DateTimeImmutable|null $date)
{
$this->datePayment = $date;
return $this;
}
public function getDatePayment()
{
return $this->datePayment;
}
public function getIsAutoPayment()
{
return $this->isAutoPayment;
}
public function setIsAutoPayment($value)
{
$this->isAutoPayment = $value;
return $this;
}
public function getIsPaid()
{
return $this->isPaid;
}
public function setIsPaid($value)
{
$this->isPaid = $value;
return $this;
}
public function getIsSentTo1C()
{
return $this->isSentTo1C;
}
public function setIsSentTo1C($value)
{
$this->isSentTo1C = $value;
return $this;
}
public function getErrorSentTo1C()
{
return $this->errorSentTo1C;
}
public function setErrorSentTo1C($error)
{
$this->errorSentTo1C = $error;
return $this;
}
public function getCar()
{
return $this->car;
}
public function setCar($car)
{
$this->car = $car;
return $this;
}
public function getIsHide()
{
return $this->isHide;
}
public function setIsHide($value)
{
$this->isHide = $value;
return $this;
}
public function getCreatedAt()
{
return $this->createdAt;
}
public function getUpdatedAt()
{
return $this->updatedAt;
}
}