src/Evo/Infrastructure/MappingORM/LetterForward.php line 36

Open in your IDE?
  1. <?php
  2. namespace Evo\Infrastructure\MappingORM;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  8. use ApiPlatform\Core\Serializer\Filter\GroupFilter;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Gedmo\Mapping\Annotation as Gedmo;
  13. use Symfony\Component\Serializer\Annotation\Groups;
  14. use Symfony\Component\Serializer\Annotation\MaxDepth;
  15. /**
  16.  * @ApiResource(attributes={
  17.  *     "normalization_context"={"groups"={"read_letter_forward"}},
  18.  *     "denormalization_context"={"groups"={"write_letter_forward"}}
  19.  * }, itemOperations={"get", "put"})
  20.  * @ApiFilter(OrderFilter::class, arguments={"orderParameterName"="order"})
  21.  * @ApiFilter(SearchFilter::class,
  22.  *     properties={
  23.  *          "organization": "exact",
  24.  *          "trackingNumber": "exact",
  25.  *          "organization.store": "exact",
  26.  *          "organization.id": "exact"
  27.  *     }
  28.  * )
  29.  * @ApiFilter(DateFilter::class, properties={"createdAt"})
  30.  * @ApiFilter(GroupFilter::class, arguments={"parameterName": "groups", "overrideDefaultGroups": true})
  31.  * @ORM\Entity(repositoryClass="App\Repository\LetterForwardRepository")
  32.  */
  33. class LetterForward
  34. {
  35.     /**
  36.      * @ORM\Id()
  37.      * @ORM\GeneratedValue()
  38.      * @Groups({"read_letter_forward", "read_organization", "read_letter", "admin:read:letter"})
  39.      * @ORM\Column(type="integer")
  40.      */
  41.     private ?int $id null;
  42.     /**
  43.      * @Groups({"read_letter_forward", "write_letter_forward", "read_organization", "read_npai"})
  44.      * @ORM\OneToMany(targetEntity="Evo\Infrastructure\MappingORM\Letter", mappedBy="letterForward", cascade={"persist"})
  45.      */
  46.     private ?Collection $letters;
  47.     /**
  48.      * @Groups({"read_letter_forward", "write_letter_forward", "read_organization", "read_letter", "read_npai", "admin:read:letter"})
  49.      * @ORM\Column(type="datetime")
  50.      */
  51.     private ?\DateTimeInterface $createdAt;
  52.     /**
  53.      * @Groups({"read_letter_forward", "write_letter_forward", "read_organization", "read_letter"})
  54.      * @Gedmo\Timestampable(on="update")
  55.      * @ORM\Column(type="datetime")
  56.      */
  57.     private ?\DateTimeInterface $updatedAt null;
  58.     /**
  59.      * @Groups({"read_letter_forward", "write_letter_forward", "read_organization"})
  60.      * @ORM\Column(type="boolean")
  61.      */
  62.     private $isDone;
  63.     /**
  64.      * @Groups({"read_letter_forward", "write_letter_forward", "read_organization", "read_letter"})
  65.      * @ORM\Column(type="string", length=255, nullable=true)
  66.      */
  67.     private ?string $comment null;
  68.     /**
  69.      * @Groups({"read_letter_forward", "write_letter_forward", "read_organization", "read_letter", "read_npai"})
  70.      * @ORM\Column(type="boolean", nullable=true)
  71.      */
  72.     private $NPAI;
  73.     /**
  74.      * @Groups({"read_letter_forward", "write_letter_forward", "read_organization", "read_npai"})
  75.      * @MaxDepth(1)
  76.      * @ORM\ManyToOne(targetEntity="Evo\Infrastructure\MappingORM\Organization", inversedBy="forwardedLetters")
  77.      */
  78.     private ?Organization $organization null;
  79.     /**
  80.      * @Groups({"read_letter_forward", "write_letter_forward", "read_organization", "read_letter"})
  81.      * @ORM\Column(type="float")
  82.      */
  83.     private $priceWithoutTax 0;
  84.     /**
  85.      * @Groups({"read_letter_forward", "write_letter_forward", "read_organization", "read_letter"})
  86.      * @ORM\Column(type="string", length=255, nullable=true)
  87.      */
  88.     private ?string $trackingNumber null;
  89.     /**
  90.      * @Groups({"read_letter_forward", "write_letter_forward", "read_organization", "read_letter"})
  91.      * @ORM\Column(type="float")
  92.      */
  93.     private $price 0;
  94.     /**
  95.      * @Groups({"read_letter_forward", "write_letter_forward", "read_organization", "read_letter"})
  96.      * @ORM\Column(type="float", nullable=true)
  97.      */
  98.     private $daysKeep;
  99.     /**
  100.      * @Groups({"read_letter_forward"})
  101.      * @ORM\OneToOne(targetEntity="Evo\Infrastructure\MappingORM\Invoice", inversedBy="letterForward", cascade={"persist", "remove"})
  102.      */
  103.     private ?Invoice $invoice null;
  104.     public function __construct()
  105.     {
  106.         $this->letters = new ArrayCollection();
  107.         $this->isDone false;
  108.         $this->NPAI false;
  109.         $this->createdAt = new \DateTime();
  110.     }
  111.     public function getId(): ?int
  112.     {
  113.         return $this->id;
  114.     }
  115.     /**
  116.      * @return Collection|Letter[]
  117.      */
  118.     public function getLetters(): Collection
  119.     {
  120.         return $this->letters;
  121.     }
  122.     public function addLetter(Letter $letter): self
  123.     {
  124.         if (!$this->letters->contains($letter)) {
  125.             $this->letters[] = $letter;
  126.             $letter->setLetterForward($this);
  127.         }
  128.         return $this;
  129.     }
  130.     public function removeLetter(Letter $letter): self
  131.     {
  132.         if ($this->letters->contains($letter)) {
  133.             $this->letters->removeElement($letter);
  134.             // set the owning side to null (unless already changed)
  135.             if ($letter->getLetterForward() === $this) {
  136.                 $letter->setLetterForward(null);
  137.             }
  138.         }
  139.         return $this;
  140.     }
  141.     public function getCreatedAt(): \DateTimeInterface
  142.     {
  143.         return $this->createdAt;
  144.     }
  145.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  146.     {
  147.         $this->createdAt $createdAt;
  148.         return $this;
  149.     }
  150.     public function getUpdatedAt(): ?\DateTimeInterface
  151.     {
  152.         return $this->updatedAt;
  153.     }
  154.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  155.     {
  156.         $this->updatedAt $updatedAt;
  157.         return $this;
  158.     }
  159.     public function getIsDone(): ?bool
  160.     {
  161.         return $this->isDone;
  162.     }
  163.     public function setIsDone(bool $isDone): self
  164.     {
  165.         $this->isDone $isDone;
  166.         return $this;
  167.     }
  168.     public function getComment(): ?string
  169.     {
  170.         return $this->comment;
  171.     }
  172.     public function setComment(?string $comment): self
  173.     {
  174.         $this->comment $comment;
  175.         return $this;
  176.     }
  177.     public function getNPAI(): ?bool
  178.     {
  179.         return $this->NPAI;
  180.     }
  181.     public function setNPAI(?bool $NPAI): self
  182.     {
  183.         $this->NPAI $NPAI;
  184.         return $this;
  185.     }
  186.     public function getOrganization(): ?Organization
  187.     {
  188.         return $this->organization;
  189.     }
  190.     public function setOrganization(?Organization $organization): self
  191.     {
  192.         $this->organization $organization;
  193.         return $this;
  194.     }
  195.     public function getPriceWithoutTax(): ?float
  196.     {
  197.         return $this->priceWithoutTax;
  198.     }
  199.     public function setPriceWithoutTax(float $priceWithoutTax): self
  200.     {
  201.         $this->priceWithoutTax $priceWithoutTax;
  202.         return $this;
  203.     }
  204.     public function getTrackingNumber(): ?string
  205.     {
  206.         return $this->trackingNumber;
  207.     }
  208.     public function setTrackingNumber(string $trackingNumber): self
  209.     {
  210.         $this->trackingNumber $trackingNumber;
  211.         return $this;
  212.     }
  213.     public function __toString()
  214.     {
  215.         return $this->getTrackingNumber() ?? '#'.$this->getId();
  216.     }
  217.     public function getPrice(): ?float
  218.     {
  219.         return $this->price;
  220.     }
  221.     public function setPrice(float $price): self
  222.     {
  223.         $this->price $price;
  224.         return $this;
  225.     }
  226.     public function getDaysKeep(): ?int
  227.     {
  228.         return $this->daysKeep;
  229.     }
  230.     public function setDaysKeep(int $daysKeep): self
  231.     {
  232.         $this->daysKeep $daysKeep;
  233.         return $this;
  234.     }
  235.     public function getInvoice(): ?Invoice
  236.     {
  237.         return $this->invoice;
  238.     }
  239.     public function setInvoice(?Invoice $invoice): self
  240.     {
  241.         $this->invoice $invoice;
  242.         return $this;
  243.     }
  244. }