src/Entity/Expense.php line 31
<?php
namespace App\Entity;
use DateTime;
use App\Entity\Company;
use Symfony\Component\Uid\Ulid;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\ExpenseRepository;
use ApiPlatform\Core\Annotation\ApiResource;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
use Symfony\Component\Serializer\Annotation\Groups;
use Gedmo\Mapping\Annotation as Gedmo;
#[ORM\Entity(repositoryClass: ExpenseRepository::class)]
#[Gedmo\SoftDeleteable(fieldName: 'deletedAt', timeAware: false, hardDelete: true)]
#[ORM\HasLifecycleCallbacks]
#[ApiResource(
attributes: ["security" => "is_granted('IS_AUTHENTICATED_FULLY')"],
collectionOperations: [
'get' => [
'normalization_context' => [
'groups' => [
'read:expense:basic',
'read:expensecategory:basic',
]
]
],
],
)]
class Expense
{
use Timestamps;
#[ORM\Id]
#[ORM\Column(type: 'ulid', unique: true)]
#[ORM\GeneratedValue(strategy: "CUSTOM")]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
#[Groups(['read:expense:basic'])]
private ?Ulid $id = null;
#[ORM\Column(type: 'string', length: 255)]
#[Groups(['read:expense:basic'])]
private $name;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['read:expense:basic'])]
private $reference;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['read:expense:basic'])]
private $description;
#[ORM\Column(type: 'datetime')]
#[Groups(['read:expense:basic'])]
private $date;
#[ORM\Column(type: 'float')]
#[Groups(['read:expense:basic'])]
private $amount = 0;
#[ORM\ManyToOne(targetEntity: Company::class, inversedBy: 'expenses')]
#[ORM\JoinColumn(nullable: false)]
private $owner;
#[ORM\ManyToOne(targetEntity: ExpenseCategory::class, inversedBy: 'expenses')]
#[Groups(['read:expense:basic'])]
private $type;
#[ORM\ManyToOne(targetEntity: Season::class, inversedBy: 'expenses')]
#[ORM\JoinColumn(nullable: false)]
private $season;
public function __construct()
{
$this->date = new DateTime();
}
public function getId(): ?Ulid
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getReference(): ?string
{
return $this->reference;
}
public function setReference(?string $reference): self
{
$this->reference = $reference;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getDate(): ?\DateTimeInterface
{
return $this->date;
}
public function setDate(\DateTimeInterface $date): self
{
$this->date = $date;
return $this;
}
public function getAmount(): ?float
{
return $this->amount;
}
public function setAmount(float $amount): self
{
$this->amount = $amount;
return $this;
}
public function getOwner(): ?Company
{
return $this->owner;
}
public function setOwner(?Company $owner): self
{
$this->owner = $owner;
return $this;
}
public function getType(): ?ExpenseCategory
{
return $this->type;
}
public function setType(?ExpenseCategory $type): self
{
$this->type = $type;
return $this;
}
public function getSeason(): ?Season
{
return $this->season;
}
public function setSeason(?Season $season): self
{
$this->season = $season;
return $this;
}
}