src/Entity/Order.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use OpenApi\Annotations as OA;
  7. use Symfony\Component\Serializer\Annotation\Groups;
  8. use Symfony\Component\Uid\Uuid;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. /**
  11.  * @ORM\Entity()
  12.  * @ORM\Table(name="`order`")
  13.  */
  14. class Order
  15. {
  16.     public const PRECISION 2;
  17.     public const SOURCE_WEB 'web';
  18.     public const SOURCE_INT 'internal';
  19.     /**
  20.      * @ORM\Id
  21.      * @ORM\Column(type="uuid", unique=true)
  22.      * @ORM\GeneratedValue(strategy="CUSTOM")
  23.      * @ORM\CustomIdGenerator(class="doctrine.uuid_generator")
  24.      * @OA\Property(type="string", format="uuid")
  25.      */
  26.     #[Groups(['index''orderHistory'])]
  27.     protected ?Uuid $id null;
  28.     /**
  29.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="orders")
  30.      * @ORM\JoinColumn(nullable=false)
  31.      */
  32.     #[Groups(['index'])]
  33.     private ?User $user;
  34.     /**
  35.      * @ORM\ManyToOne(targetEntity=Vin::class, inversedBy="orders", fetch="EAGER")
  36.      * @ORM\JoinColumn(nullable=false)
  37.      */
  38.     #[Groups(['vin''orderHistory'])]
  39.     private ?Vin $vin;
  40.     /**
  41.      * @ORM\Column(type="string", length=255, nullable=true)
  42.      */
  43.     #[Groups(['index''orderHistory'])]
  44.     #[Assert\Email]
  45.     private ?string $email null;
  46.     /**
  47.      * @ORM\Column(type="decimal", precision=10, scale=2)
  48.      */
  49.     #[Groups(['index'])]
  50.     private ?float $totalSum null;
  51.     /**
  52.      * @ORM\Column(type="boolean")
  53.      */
  54.     #[Groups(['index''orderHistory'])]
  55.     private bool $paid false;
  56.     /**
  57.      * @ORM\Column(type="boolean")
  58.      */
  59.     #[Groups(['index''orderHistory'])]
  60.     private bool $emailSent false;
  61.     /**
  62.      * @ORM\Column(type="datetime")
  63.      */
  64.     #[Groups(['orderHistory'])]
  65.     private ?\DateTimeInterface $createdAt null;
  66.     /**
  67.      * @ORM\OneToMany(targetEntity=Report::class, mappedBy="order", cascade={"persist"})
  68.      */
  69.     #[Groups(['report''orderHistory'])]
  70.     private Collection $reports;
  71.     #[Groups(['index'])]
  72.     private ?string $merchantId null;
  73.     #[Groups(['index'])]
  74.     private ?string $payLink null;
  75.     /**
  76.      * @ORM\Column(type="string", length=255, nullable=true)
  77.      */
  78.     #[Groups(['index'])]
  79.     private ?string $reportLink null;
  80.     /**
  81.      * @ORM\Column(type="string", length=255, nullable=true)
  82.      */
  83.     private ?string $source null;
  84.     /**
  85.      * @ORM\ManyToOne(targetEntity=Promocode::class)
  86.      */
  87.     private ?Promocode $promocode null;
  88.     /**
  89.      * @ORM\Column(type="boolean", nullable=true)
  90.      */
  91.     private ?bool $emailPreReportSend false;
  92.     public function __construct()
  93.     {
  94.         $this->reports = new ArrayCollection();
  95.     }
  96.     public function __toString(): string
  97.     {
  98.         return $this->id '_' $this->getVin()?->getVin();
  99.     }
  100.     public function getId(): ?Uuid
  101.     {
  102.         return $this->id;
  103.     }
  104.     public function getUser(): ?User
  105.     {
  106.         return $this->user;
  107.     }
  108.     public function setUser(?User $user): self
  109.     {
  110.         $this->user $user;
  111.         return $this;
  112.     }
  113.     public function getVin(): ?Vin
  114.     {
  115.         return $this->vin;
  116.     }
  117.     public function setVin(?Vin $vin): self
  118.     {
  119.         $this->vin $vin;
  120.         return $this;
  121.     }
  122.     public function getEmail(): ?string
  123.     {
  124.         return $this->email;
  125.     }
  126.     public function setEmail(?string $email): self
  127.     {
  128.         $this->email $email;
  129.         return $this;
  130.     }
  131.     public function getTotalSum(): ?float
  132.     {
  133.         return $this->totalSum;
  134.     }
  135.     public function setTotalSum(float $totalSum): self
  136.     {
  137.         $this->totalSum \round($totalSumself::PRECISION);
  138.         return $this;
  139.     }
  140.     public function getPaid(): bool
  141.     {
  142.         return $this->paid;
  143.     }
  144.     public function setPaid(bool $paid): self
  145.     {
  146.         $this->paid $paid;
  147.         return $this;
  148.     }
  149.     public function getEmailSent(): bool
  150.     {
  151.         return $this->emailSent;
  152.     }
  153.     public function setEmailSent(bool $emailSent true): Order
  154.     {
  155.         $this->emailSent $emailSent;
  156.         return $this;
  157.     }
  158.     public function getCreatedAt(): ?\DateTimeInterface
  159.     {
  160.         return $this->createdAt;
  161.     }
  162.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  163.     {
  164.         $this->createdAt $createdAt;
  165.         return $this;
  166.     }
  167.     public function getReports(): Collection
  168.     {
  169.         return $this->reports;
  170.     }
  171.     public function addReport(Report $report): self
  172.     {
  173.         if (!$this->reports->contains($report)) {
  174.             $this->reports[] = $report;
  175.             $report->setOrder($this);
  176.         }
  177.         return $this;
  178.     }
  179.     public function removeReport(Report $report): self
  180.     {
  181.         if ($this->reports->removeElement($report)) {
  182.             if ($report->getOrder() === $this) {
  183.                 $report->setOrder(null);
  184.             }
  185.         }
  186.         return $this;
  187.     }
  188.     public function getMerchantId(): ?string
  189.     {
  190.         return $this->merchantId;
  191.     }
  192.     public function setMerchantId(?string $merchantId): self
  193.     {
  194.         $this->merchantId $merchantId;
  195.         return $this;
  196.     }
  197.     public function getPayLink(): ?string
  198.     {
  199.         return $this->payLink;
  200.     }
  201.     public function setPayLink(?string $payLink): self
  202.     {
  203.         $this->payLink $payLink;
  204.         return $this;
  205.     }
  206.     public function toLog(): array
  207.     {
  208.         return [
  209.             'orderId' => (string) $this->id,
  210.             'vin' => (string) $this->vin,
  211.             'email' => $this->email,
  212.             'source' => (string) $this->getSource(),
  213.         ];
  214.     }
  215.     public function getPromocode(): ?Promocode
  216.     {
  217.         return $this->promocode;
  218.     }
  219.     public function setPromocode(?Promocode $promocode): self
  220.     {
  221.         $this->promocode $promocode;
  222.         return $this;
  223.     }
  224.     public function getReportLink(): ?string
  225.     {
  226.         return $this->reportLink;
  227.     }
  228.     public function setReportLink(?string $reportLink): self
  229.     {
  230.         $this->reportLink $reportLink;
  231.         return $this;
  232.     }
  233.     /**
  234.      * @return string|null
  235.      */
  236.     public function getSource(): ?string
  237.     {
  238.         return $this->source;
  239.     }
  240.     public function setSource(?string $source): self
  241.     {
  242.         $this->source $source;
  243.         return $this;
  244.     }
  245.     public function getEmailPreReportSend(): ?bool
  246.     {
  247.         return $this->emailPreReportSend;
  248.     }
  249.     public function setEmailPreReportSend(?bool $emailPreReportSend true): self
  250.     {
  251.         $this->emailPreReportSend $emailPreReportSend;
  252.         return $this;
  253.     }
  254. }