src/Entity/Expense.php line 31

  1. <?php
  2. namespace App\Entity;
  3. use DateTime;
  4. use App\Entity\Company;
  5. use Symfony\Component\Uid\Ulid;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use App\Repository\ExpenseRepository;
  8. use ApiPlatform\Core\Annotation\ApiResource;
  9. use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. use Gedmo\Mapping\Annotation as Gedmo;
  12. #[ORM\Entity(repositoryClassExpenseRepository::class)]
  13. #[Gedmo\SoftDeleteable(fieldName'deletedAt'timeAwarefalsehardDeletetrue)]
  14. #[ORM\HasLifecycleCallbacks]
  15. #[ApiResource(
  16.     attributes: ["security" => "is_granted('IS_AUTHENTICATED_FULLY')"],
  17.     collectionOperations: [
  18.         'get' => [
  19.             'normalization_context' => [
  20.                 'groups' => [
  21.                     'read:expense:basic',
  22.                     'read:expensecategory:basic',
  23.                 ]
  24.             ]
  25.         ],
  26.     ],
  27. )]
  28. class Expense
  29. {
  30.     use Timestamps;
  31.     #[ORM\Id]
  32.     #[ORM\Column(type'ulid'uniquetrue)]
  33.     #[ORM\GeneratedValue(strategy"CUSTOM")]
  34.     #[ORM\CustomIdGenerator(class: UlidGenerator::class)]
  35.     #[Groups(['read:expense:basic'])]
  36.     private ?Ulid $id null;
  37.     #[ORM\Column(type'string'length255)]
  38.     #[Groups(['read:expense:basic'])]
  39.     private $name;
  40.     #[ORM\Column(type'string'length255nullabletrue)]
  41.     #[Groups(['read:expense:basic'])]
  42.     private $reference;
  43.     #[ORM\Column(type'string'length255nullabletrue)]
  44.     #[Groups(['read:expense:basic'])]
  45.     private $description;
  46.     #[ORM\Column(type'datetime')]
  47.     #[Groups(['read:expense:basic'])]
  48.     private $date;
  49.     #[ORM\Column(type'float')]
  50.     #[Groups(['read:expense:basic'])]
  51.     private $amount 0;
  52.     #[ORM\ManyToOne(targetEntityCompany::class, inversedBy'expenses')]
  53.     #[ORM\JoinColumn(nullablefalse)]
  54.     private $owner;
  55.     #[ORM\ManyToOne(targetEntityExpenseCategory::class, inversedBy'expenses')]
  56.     #[Groups(['read:expense:basic'])]
  57.     private $type;
  58.     #[ORM\ManyToOne(targetEntitySeason::class, inversedBy'expenses')]
  59.     #[ORM\JoinColumn(nullablefalse)]
  60.     private $season;
  61.     public function __construct()
  62.     {
  63.         $this->date = new DateTime();
  64.     }
  65.     public function getId(): ?Ulid
  66.     {
  67.         return $this->id;
  68.     }
  69.     public function getName(): ?string
  70.     {
  71.         return $this->name;
  72.     }
  73.     public function setName(string $name): self
  74.     {
  75.         $this->name $name;
  76.         return $this;
  77.     }
  78.     public function getReference(): ?string
  79.     {
  80.         return $this->reference;
  81.     }
  82.     public function setReference(?string $reference): self
  83.     {
  84.         $this->reference $reference;
  85.         return $this;
  86.     }
  87.     public function getDescription(): ?string
  88.     {
  89.         return $this->description;
  90.     }
  91.     public function setDescription(?string $description): self
  92.     {
  93.         $this->description $description;
  94.         return $this;
  95.     }
  96.     public function getDate(): ?\DateTimeInterface
  97.     {
  98.         return $this->date;
  99.     }
  100.     public function setDate(\DateTimeInterface $date): self
  101.     {
  102.         $this->date $date;
  103.         return $this;
  104.     }
  105.     public function getAmount(): ?float
  106.     {
  107.         return $this->amount;
  108.     }
  109.     public function setAmount(float $amount): self
  110.     {
  111.         $this->amount $amount;
  112.         return $this;
  113.     }
  114.     public function getOwner(): ?Company
  115.     {
  116.         return $this->owner;
  117.     }
  118.     public function setOwner(?Company $owner): self
  119.     {
  120.         $this->owner $owner;
  121.         return $this;
  122.     }
  123.     public function getType(): ?ExpenseCategory
  124.     {
  125.         return $this->type;
  126.     }
  127.     public function setType(?ExpenseCategory $type): self
  128.     {
  129.         $this->type $type;
  130.         return $this;
  131.     }
  132.     public function getSeason(): ?Season
  133.     {
  134.         return $this->season;
  135.     }
  136.     public function setSeason(?Season $season): self
  137.     {
  138.         $this->season $season;
  139.         return $this;
  140.     }
  141. }