<?php
namespace Evo\Infrastructure\MappingORM;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Serializer\Filter\GroupFilter;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;
/**
* @ApiResource(attributes={
* "normalization_context"={"groups"={"read_letter_forward"}},
* "denormalization_context"={"groups"={"write_letter_forward"}}
* }, itemOperations={"get", "put"})
* @ApiFilter(OrderFilter::class, arguments={"orderParameterName"="order"})
* @ApiFilter(SearchFilter::class,
* properties={
* "organization": "exact",
* "trackingNumber": "exact",
* "organization.store": "exact",
* "organization.id": "exact"
* }
* )
* @ApiFilter(DateFilter::class, properties={"createdAt"})
* @ApiFilter(GroupFilter::class, arguments={"parameterName": "groups", "overrideDefaultGroups": true})
* @ORM\Entity(repositoryClass="App\Repository\LetterForwardRepository")
*/
class LetterForward
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @Groups({"read_letter_forward", "read_organization", "read_letter", "admin:read:letter"})
* @ORM\Column(type="integer")
*/
private ?int $id = null;
/**
* @Groups({"read_letter_forward", "write_letter_forward", "read_organization", "read_npai"})
* @ORM\OneToMany(targetEntity="Evo\Infrastructure\MappingORM\Letter", mappedBy="letterForward", cascade={"persist"})
*/
private ?Collection $letters;
/**
* @Groups({"read_letter_forward", "write_letter_forward", "read_organization", "read_letter", "read_npai", "admin:read:letter"})
* @ORM\Column(type="datetime")
*/
private ?\DateTimeInterface $createdAt;
/**
* @Groups({"read_letter_forward", "write_letter_forward", "read_organization", "read_letter"})
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime")
*/
private ?\DateTimeInterface $updatedAt = null;
/**
* @Groups({"read_letter_forward", "write_letter_forward", "read_organization"})
* @ORM\Column(type="boolean")
*/
private $isDone;
/**
* @Groups({"read_letter_forward", "write_letter_forward", "read_organization", "read_letter"})
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $comment = null;
/**
* @Groups({"read_letter_forward", "write_letter_forward", "read_organization", "read_letter", "read_npai"})
* @ORM\Column(type="boolean", nullable=true)
*/
private $NPAI;
/**
* @Groups({"read_letter_forward", "write_letter_forward", "read_organization", "read_npai"})
* @MaxDepth(1)
* @ORM\ManyToOne(targetEntity="Evo\Infrastructure\MappingORM\Organization", inversedBy="forwardedLetters")
*/
private ?Organization $organization = null;
/**
* @Groups({"read_letter_forward", "write_letter_forward", "read_organization", "read_letter"})
* @ORM\Column(type="float")
*/
private $priceWithoutTax = 0;
/**
* @Groups({"read_letter_forward", "write_letter_forward", "read_organization", "read_letter"})
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $trackingNumber = null;
/**
* @Groups({"read_letter_forward", "write_letter_forward", "read_organization", "read_letter"})
* @ORM\Column(type="float")
*/
private $price = 0;
/**
* @Groups({"read_letter_forward", "write_letter_forward", "read_organization", "read_letter"})
* @ORM\Column(type="float", nullable=true)
*/
private $daysKeep;
/**
* @Groups({"read_letter_forward"})
* @ORM\OneToOne(targetEntity="Evo\Infrastructure\MappingORM\Invoice", inversedBy="letterForward", cascade={"persist", "remove"})
*/
private ?Invoice $invoice = null;
public function __construct()
{
$this->letters = new ArrayCollection();
$this->isDone = false;
$this->NPAI = false;
$this->createdAt = new \DateTime();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @return Collection|Letter[]
*/
public function getLetters(): Collection
{
return $this->letters;
}
public function addLetter(Letter $letter): self
{
if (!$this->letters->contains($letter)) {
$this->letters[] = $letter;
$letter->setLetterForward($this);
}
return $this;
}
public function removeLetter(Letter $letter): self
{
if ($this->letters->contains($letter)) {
$this->letters->removeElement($letter);
// set the owning side to null (unless already changed)
if ($letter->getLetterForward() === $this) {
$letter->setLetterForward(null);
}
}
return $this;
}
public function getCreatedAt(): \DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getIsDone(): ?bool
{
return $this->isDone;
}
public function setIsDone(bool $isDone): self
{
$this->isDone = $isDone;
return $this;
}
public function getComment(): ?string
{
return $this->comment;
}
public function setComment(?string $comment): self
{
$this->comment = $comment;
return $this;
}
public function getNPAI(): ?bool
{
return $this->NPAI;
}
public function setNPAI(?bool $NPAI): self
{
$this->NPAI = $NPAI;
return $this;
}
public function getOrganization(): ?Organization
{
return $this->organization;
}
public function setOrganization(?Organization $organization): self
{
$this->organization = $organization;
return $this;
}
public function getPriceWithoutTax(): ?float
{
return $this->priceWithoutTax;
}
public function setPriceWithoutTax(float $priceWithoutTax): self
{
$this->priceWithoutTax = $priceWithoutTax;
return $this;
}
public function getTrackingNumber(): ?string
{
return $this->trackingNumber;
}
public function setTrackingNumber(string $trackingNumber): self
{
$this->trackingNumber = $trackingNumber;
return $this;
}
public function __toString()
{
return $this->getTrackingNumber() ?? '#'.$this->getId();
}
public function getPrice(): ?float
{
return $this->price;
}
public function setPrice(float $price): self
{
$this->price = $price;
return $this;
}
public function getDaysKeep(): ?int
{
return $this->daysKeep;
}
public function setDaysKeep(int $daysKeep): self
{
$this->daysKeep = $daysKeep;
return $this;
}
public function getInvoice(): ?Invoice
{
return $this->invoice;
}
public function setInvoice(?Invoice $invoice): self
{
$this->invoice = $invoice;
return $this;
}
}