src/Entity/OrderItems.php line 13

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\OrderItemsRepository;
  4. use DateTimeInterface;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Serializer\Annotation\Groups;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. #[ORM\Entity(repositoryClass: OrderItemsRepository::class)]
  10. class OrderItems
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id = null;
  16.     #[ORM\ManyToOne(inversedBy: 'orderItems')]
  17.     #[ORM\JoinColumn(nullable: false)]
  18.     private ?Order $command = null;
  19.     #[ORM\Column]
  20.     #[Assert\Type(type: 'integer')]
  21.     #[Groups(['order:list', 'order:new'])]
  22.     private ?int $quantity = 1;
  23.     #[ORM\Column]
  24.     #[Groups(['order:list'])]
  25.     private ?float $amount = null;
  26.     #[ORM\ManyToOne(cascade: ['persist', 'remove'], inversedBy: 'orderItems')]
  27.     #[ORM\JoinColumn(nullable: false)]
  28.     #[Groups(['order:list', 'order:new'])]
  29.     private ?ArticleDepartment $article = null;
  30.     #[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
  31.     private ?DateTimeInterface $createdAt = null;
  32.     public function __construct()
  33.     {
  34.         if (is_null($this->createdAt))
  35.             $this->createdAt = new \DateTime();
  36.     }
  37.     public function getId(): ?int
  38.     {
  39.         return $this->id;
  40.     }
  41.     public function getCommand(): ?Order
  42.     {
  43.         return $this->command;
  44.     }
  45.     public function setCommand(?Order $command): self
  46.     {
  47.         $this->command = $command;
  48.         return $this;
  49.     }
  50.     public function getQuantity(): ?int
  51.     {
  52.         return $this->quantity;
  53.     }
  54.     public function setQuantity(int $quantity): self
  55.     {
  56.         $this->quantity = $quantity;
  57.         return $this;
  58.     }
  59.     public function getAmount(): ?float
  60.     {
  61.         if ($this->getController())
  62.             return $this->getController();
  63.         return $this->amount;
  64.     }
  65.     public function setAmount(float $amount): self
  66.     {
  67.         $this->amount = $amount;
  68.         return $this;
  69.     }
  70.     public function getArticle(): ?ArticleDepartment
  71.     {
  72.         return $this->article;
  73.     }
  74.     public function setArticle(?ArticleDepartment $article): self
  75.     {
  76.         $this->article = $article;
  77.         return $this;
  78.     }
  79.     public function getController(): float|bool
  80.     {
  81.         return $this->getArticle()->getController();
  82.     }
  83.     public function getCreatedAt(): ?DateTimeInterface
  84.     {
  85.         return $this->createdAt;
  86.     }
  87.     public function setCreatedAt(?DateTimeInterface $createdAt): self
  88.     {
  89.         $this->createdAt = $createdAt;
  90.         return $this;
  91.     }
  92. }