<?php
declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiProperty;
use App\Trait\TimestampableEntity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
#[ORM\Entity]
#[ApiResource(
iri: 'Payment',
collectionOperations: [],
itemOperations: [
'get' => [
'security' => "is_granted('ROLE_USER')",
'method' => 'GET',
'path' => '/contracts/payments/{id}',
'openapi_context' => [
'tags' => ['Contract / Payment']
]
]
],
attributes: ['pagination_enabled' => false]
)]
class Payment
{
use TimestampableEntity;
public const PAYMENT_STATUS_INVOICED = 'INVOICED';
public const PAYMENT_STATUS_NOT_INVOICED = 'NOT_INVOICED';
public const PAYMENT_STATUS_PAID = 'PAID';
public const PAYMENT_STATUS_CANCELED = 'CANCELED';
public const PAYMENT_STATUSES = [
self::PAYMENT_STATUS_INVOICED,
self::PAYMENT_STATUS_NOT_INVOICED,
self::PAYMENT_STATUS_PAID,
self::PAYMENT_STATUS_CANCELED,
];
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'NONE')]
#[ORM\Column(type: 'uuid', unique: true)]
private ?UuidInterface $id = null;
#[ORM\Column(type: 'string', nullable: true)]
#[Assert\NotBlank]
#[Assert\Type('string')]
#[ApiProperty()]
#[Groups([
'contract:collection:post',
'contract:item:get',
'contract:item:put'
])]
private ?string $amount = null;
#[ORM\Column(type: 'string', nullable: true)]
#[Assert\Type('string')]
#[ApiProperty()]
#[Groups([
'contract:collection:post',
'contract:item:get',
'contract:item:put'
])]
private ?string $amountCurrency = null;
#[ORM\Column(type: 'date', nullable: true)]
#[Assert\NotBlank]
#[Assert\Type(\DateTimeInterface::class)]
#[ApiProperty()]
#[Groups([
'contract:collection:post',
'contract:item:get',
'contract:item:put'
])]
private ?\DateTimeInterface $dueDate = null;
#[ORM\Column(type: 'string', nullable: true)]
#[ApiProperty()]
#[Assert\Type('string')]
#[Groups([
'contract:collection:post',
'contract:item:get',
'contract:item:put'
])]
private ?string $description = null;
#[ORM\Column(type: 'string', nullable: false)]
#[Assert\NotNull]
#[Assert\Type('string')]
#[Assert\Choice(
choices: self::PAYMENT_STATUSES,
message: 'The status is not valid.'
)]
#[ApiProperty()]
#[Groups([
'contract:collection:post',
'contract:item:get',
'contract:item:put'
])]
private ?string $status = self::PAYMENT_STATUS_NOT_INVOICED;
#[ORM\ManyToOne(
targetEntity: Contract::class,
inversedBy: 'payments'
)]
#[ORM\JoinColumn(nullable: true)]
private ?Contract $contract = null;
public function __construct()
{
$this->id = Uuid::uuid4();
}
public function getId(): ?UuidInterface
{
return $this->id;
}
public function setAmount(?string $amount): void
{
$this->amount = $amount;
}
public function getAmount(): ?string
{
return $this->amount;
}
public function getAmountCurrency(): ?string
{
return $this->amountCurrency;
}
public function setAmountCurrency(?string $amountCurrency): void
{
$this->amountCurrency = $amountCurrency;
}
public function setDueDate(?\DateTimeInterface $dueDate): void
{
$this->dueDate = $dueDate;
}
public function getDueDate(): ?string
{
return $this->dueDate ? $this->dueDate->format('Y-m-d') : null;
}
public function setDescription(?string $description): void
{
$this->description = $description;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setStatus(?string $status): void
{
$this->status = $status;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setContract(?Contract $contract): void
{
$this->contract = $contract;
}
public function getContract(): ?Contract
{
return $this->contract;
}
}