src/Entity/Order.php line 12

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\OrderRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClassOrderRepository::class)]
  8. #[ORM\Table(name'`order`')]
  9. class Order
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\ManyToOne(inversedBy'orders')]
  16.     private ?Customer $customer null;
  17.     #[ORM\Column]
  18.     private ?float $total null;
  19.     #[ORM\Column]
  20.     private ?\DateTimeImmutable $createdAt null;
  21.     #[ORM\OneToMany(mappedBy'orderRef'targetEntityOrderLine::class,cascade: ['persist','remove'])]
  22.     private Collection $orderLines;
  23.     #[ORM\OneToMany(mappedBy'orderRef'targetEntityPayment::class, cascade: ["persist",'remove'])]
  24.     private Collection $payments;
  25.     #[ORM\ManyToOne(inversedBy'orders')]
  26.     #[ORM\JoinColumn(nullablefalse)]
  27.     private ?Pos $pos null;
  28.     public function __construct()
  29.     {
  30.         $this->createdAt = new \DateTimeImmutable();
  31.         $this->orderLines = new ArrayCollection();
  32.         $this->payments = new ArrayCollection();
  33.     }
  34.     public function getId(): ?int
  35.     {
  36.         return $this->id;
  37.     }
  38.     public function getCustomer(): ?Customer
  39.     {
  40.         return $this->customer;
  41.     }
  42.     public function setCustomer(?Customer $customer): self
  43.     {
  44.         $this->customer $customer;
  45.         return $this;
  46.     }
  47.     public function getTotal(): ?float
  48.     {
  49.         return $this->total;
  50.     }
  51.     public function setTotal(float $total): self
  52.     {
  53.         $this->total $total;
  54.         return $this;
  55.     }
  56.     public function getCreatedAt(): ?\DateTimeImmutable
  57.     {
  58.         return $this->createdAt;
  59.     }
  60.     public function setCreatedAt(\DateTime $createdAt): self
  61.     {
  62.         $this->createdAt \DateTimeImmutable::createFromMutable($createdAt);
  63.         return $this;
  64.     }
  65.     /**
  66.      * @return Collection<int, OrderLine>
  67.      */
  68.     public function getOrderLines(): Collection
  69.     {
  70.         return $this->orderLines;
  71.     }
  72.     public function addOrderLine(OrderLine $orderLine): self
  73.     {
  74.         if (!$this->orderLines->contains($orderLine)) {
  75.             $this->orderLines->add($orderLine);
  76.             $orderLine->setOrderRef($this);
  77.         }
  78.         return $this;
  79.     }
  80.     public function removeOrderLine(OrderLine $orderLine): self
  81.     {
  82.         if ($this->orderLines->removeElement($orderLine)) {
  83.             // set the owning side to null (unless already changed)
  84.             if ($orderLine->getOrderRef() === $this) {
  85.                 $orderLine->setOrderRef(null);
  86.             }
  87.         }
  88.         return $this;
  89.     }
  90.     /**
  91.      * @return Collection<int, Payment>
  92.      */
  93.     public function getPayments(): Collection
  94.     {
  95.         return $this->payments;
  96.     }
  97.     public function addPayment(Payment $payment): self
  98.     {
  99.         if (!$this->payments->contains($payment)) {
  100.             $this->payments->add($payment);
  101.             $payment->setOrderRef($this);
  102.         }
  103.         return $this;
  104.     }
  105.     public function removePayment(Payment $payment): self
  106.     {
  107.         if ($this->payments->removeElement($payment)) {
  108.             // set the owning side to null (unless already changed)
  109.             if ($payment->getOrderRef() === $this) {
  110.                 $payment->setOrderRef(null);
  111.             }
  112.         }
  113.         return $this;
  114.     }
  115.     public function getPos(): ?Pos
  116.     {
  117.         return $this->pos;
  118.     }
  119.     public function setPos(?Pos $pos): self
  120.     {
  121.         $this->pos $pos;
  122.         return $this;
  123.     }
  124. }