src/Entity/Payment.php line 32

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Annotation\ApiProperty;
  6. use App\Trait\TimestampableEntity;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use Ramsey\Uuid\Uuid;
  11. use Ramsey\Uuid\UuidInterface;
  12. #[ORM\Entity]
  13. #[ApiResource(
  14.     iri'Payment',
  15.     collectionOperations: [],
  16.     itemOperations: [
  17.         'get' => [
  18.             'security' => "is_granted('ROLE_USER')",
  19.             'method' => 'GET',
  20.             'path' => '/contracts/payments/{id}',
  21.             'openapi_context' => [
  22.                 'tags' => ['Contract / Payment']
  23.             ]
  24.         ]
  25.     ],
  26.     attributes: ['pagination_enabled' => false]
  27. )]
  28. class Payment
  29. {
  30.     use TimestampableEntity;
  31.     public const PAYMENT_STATUS_INVOICED 'INVOICED';
  32.     public const PAYMENT_STATUS_NOT_INVOICED 'NOT_INVOICED';
  33.     public const PAYMENT_STATUS_PAID 'PAID';
  34.     public const PAYMENT_STATUS_CANCELED 'CANCELED';
  35.    
  36.     public const PAYMENT_STATUSES = [
  37.         self::PAYMENT_STATUS_INVOICED,
  38.         self::PAYMENT_STATUS_NOT_INVOICED,
  39.         self::PAYMENT_STATUS_PAID,
  40.         self::PAYMENT_STATUS_CANCELED,
  41.     ];
  42.     
  43.     #[ORM\Id]
  44.     #[ORM\GeneratedValue(strategy'NONE')]
  45.     #[ORM\Column(type'uuid'uniquetrue)]
  46.     private ?UuidInterface $id null;
  47.     #[ORM\Column(type'string'nullabletrue)]
  48.     #[Assert\NotBlank]
  49.     #[Assert\Type('string')]
  50.     #[ApiProperty()]
  51.     #[Groups([
  52.         'contract:collection:post'
  53.         'contract:item:get'
  54.         'contract:item:put'
  55.     ])]
  56.     private ?string $amount null;
  57.     #[ORM\Column(type'string'nullabletrue)]
  58.     #[Assert\Type('string')]
  59.     #[ApiProperty()]
  60.     #[Groups([
  61.         'contract:collection:post'
  62.         'contract:item:get'
  63.         'contract:item:put'
  64.     ])]
  65.     private ?string $amountCurrency null;
  66.     #[ORM\Column(type'date'nullabletrue)]
  67.     #[Assert\NotBlank]
  68.     #[Assert\Type(\DateTimeInterface::class)]
  69.     #[ApiProperty()]
  70.     #[Groups([
  71.         'contract:collection:post'
  72.         'contract:item:get'
  73.         'contract:item:put'
  74.     ])]
  75.     private ?\DateTimeInterface $dueDate null;
  76.     #[ORM\Column(type'string'nullabletrue)]
  77.     #[ApiProperty()]
  78.     #[Assert\Type('string')]
  79.     #[Groups([
  80.         'contract:collection:post'
  81.         'contract:item:get'
  82.         'contract:item:put'
  83.     ])]
  84.     private ?string $description null;
  85.     #[ORM\Column(type'string'nullablefalse)]
  86.     #[Assert\NotNull]
  87.     #[Assert\Type('string')]
  88.     #[Assert\Choice(
  89.         choicesself::PAYMENT_STATUSES
  90.         message'The status is not valid.'
  91.     )]
  92.     #[ApiProperty()]
  93.     #[Groups([
  94.         'contract:collection:post'
  95.         'contract:item:get'
  96.         'contract:item:put'
  97.     ])]
  98.     private ?string $status self::PAYMENT_STATUS_NOT_INVOICED;
  99.     #[ORM\ManyToOne(
  100.         targetEntityContract::class, 
  101.         inversedBy'payments'
  102.     )]
  103.     #[ORM\JoinColumn(nullabletrue)]
  104.     private ?Contract $contract null;
  105.     public function __construct()
  106.     {
  107.         $this->id Uuid::uuid4();
  108.     }
  109.     public function getId(): ?UuidInterface
  110.     {
  111.         return $this->id;
  112.     }
  113.     public function setAmount(?string $amount): void
  114.     {
  115.         $this->amount $amount;
  116.     }
  117.     public function getAmount(): ?string
  118.     {
  119.         return $this->amount;
  120.     }
  121.     public function getAmountCurrency(): ?string
  122.     {
  123.         return $this->amountCurrency;
  124.     }
  125.     public function setAmountCurrency(?string $amountCurrency): void
  126.     {
  127.         $this->amountCurrency $amountCurrency;
  128.     }
  129.     public function setDueDate(?\DateTimeInterface $dueDate): void
  130.     {
  131.         $this->dueDate $dueDate;
  132.     }
  133.     public function getDueDate(): ?string
  134.     {
  135.         return $this->dueDate $this->dueDate->format('Y-m-d') : null;
  136.     }
  137.     public function setDescription(?string $description): void
  138.     {
  139.         $this->description $description;
  140.     }
  141.     public function getDescription(): ?string
  142.     {
  143.         return $this->description;
  144.     }
  145.     public function setStatus(?string $status): void
  146.     {
  147.         $this->status $status;
  148.     }
  149.     public function getStatus(): ?string
  150.     {
  151.         return $this->status;
  152.     }
  153.     public function setContract(?Contract $contract): void
  154.     {
  155.         $this->contract $contract;
  156.     }
  157.     public function getContract(): ?Contract
  158.     {
  159.         return $this->contract;
  160.     }
  161. }