src/Entity/Order.php line 20

  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\enums\OrderStatus;
  4. use Symfony\Component\Uid\Ulid;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use App\Repository\OrderRepository;
  7. use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. #[ORM\Entity(repositoryClassOrderRepository::class)]
  10. #[Gedmo\SoftDeleteable(fieldName'deletedAt'timeAwarefalsehardDeletetrue)]
  11. #[ORM\Table(name'`order`')]
  12. #[ORM\HasLifecycleCallbacks]
  13. // #[ApiResource(
  14. //     attributes: ["security" => "is_granted('ROLE_SUPER_ADMIN')"],
  15. // )]
  16. class Order
  17. {
  18.     use Timestamps;
  19.     #[ORM\Id]
  20.     #[ORM\Column(type'ulid'uniquetrue)]
  21.     #[ORM\GeneratedValue(strategy"CUSTOM")]
  22.     #[ORM\CustomIdGenerator(class: UlidGenerator::class)]
  23.     private ?Ulid $id null;
  24.     #[ORM\Column(type'string'length255nullabletrue)]
  25.     private $name;
  26.     #[ORM\Column(type'integer')]
  27.     private $price 0;
  28.     #[ORM\Column(type'integer')]
  29.     private $quantity 1;
  30.     #[ORM\Column(type'integer')]
  31.     private $total 0;
  32.     #[ORM\Column(type'string'length255enumTypeOrderStatus::class)]
  33.     private $status;
  34.     #[ORM\ManyToOne(targetEntityUser::class, inversedBy'orders')]
  35.     #[ORM\JoinColumn(nullablefalse)]
  36.     private $customer;
  37.     #[ORM\ManyToOne(targetEntityProduct::class, inversedBy'orders')]
  38.     #[ORM\JoinColumn(nullablefalse)]
  39.     private $product;
  40.     #[ORM\ManyToOne(targetEntityCoupon::class, inversedBy'orders')]
  41.     private $coupon;
  42.     #[ORM\Column(type'string'length255nullabletrue)]
  43.     private $recipe;
  44.     #[ORM\Column(type'boolean')]
  45.     private $isPayed;
  46.     #[ORM\ManyToOne(targetEntityCompany::class, inversedBy'orders')]
  47.     #[ORM\JoinColumn(nullablefalse)]
  48.     private $owner;
  49.     public function __construct()
  50.     {
  51.         $this->status OrderStatus::DRAFT;
  52.         $this->isPayed false;
  53.     }
  54.     public function getId(): ?Ulid
  55.     {
  56.         return $this->id;
  57.     }
  58.     public function getName(): ?string
  59.     {
  60.         return $this->name;
  61.     }
  62.     public function setName(?string $name): self
  63.     {
  64.         $this->name $name;
  65.         return $this;
  66.     }
  67.     public function getPrice(): ?int
  68.     {
  69.         return $this->price;
  70.     }
  71.     public function setPrice(int $price): self
  72.     {
  73.         $this->price $price;
  74.         return $this;
  75.     }
  76.     public function getQuantity(): ?int
  77.     {
  78.         return $this->quantity;
  79.     }
  80.     public function setQuantity(int $quantity): self
  81.     {
  82.         $this->quantity $quantity;
  83.         return $this;
  84.     }
  85.     public function getTotal(): ?int
  86.     {
  87.         return $this->total;
  88.     }
  89.     public function setTotal(int $total): self
  90.     {
  91.         $this->total $total;
  92.         return $this;
  93.     }
  94.     public function getTotToPayal(): ?int
  95.     {
  96.         if ($this->coupon) {
  97.             return $this->total - ($this->total $this->coupon->getAmount() / 100);
  98.         }
  99.         return $this->total;
  100.     }
  101.     public function getStatus(): ?OrderStatus
  102.     {
  103.         return $this->status;
  104.     }
  105.     public function setStatus(OrderStatus $status): self
  106.     {
  107.         $this->status $status;
  108.         return $this;
  109.     }
  110.     public function getCustomer(): ?User
  111.     {
  112.         return $this->customer;
  113.     }
  114.     public function setCustomer(?User $customer): self
  115.     {
  116.         $this->customer $customer;
  117.         return $this;
  118.     }
  119.     public function getProduct(): ?Product
  120.     {
  121.         return $this->product;
  122.     }
  123.     public function setProduct(?Product $product): self
  124.     {
  125.         $this->product $product;
  126.         return $this;
  127.     }
  128.     public function getCoupon(): ?Coupon
  129.     {
  130.         return $this->coupon;
  131.     }
  132.     public function setCoupon(?Coupon $coupon): self
  133.     {
  134.         $this->coupon $coupon;
  135.         return $this;
  136.     }
  137.     public function getRecipe(): ?string
  138.     {
  139.         return $this->recipe;
  140.     }
  141.     public function setRecipe(?string $recipe): self
  142.     {
  143.         $this->recipe $recipe;
  144.         return $this;
  145.     }
  146.     public function isIsPayed(): ?bool
  147.     {
  148.         return $this->isPayed;
  149.     }
  150.     public function setIsPayed(bool $isPayed): self
  151.     {
  152.         $this->isPayed $isPayed;
  153.         return $this;
  154.     }
  155.     public function getOwner(): ?Company
  156.     {
  157.         return $this->owner;
  158.     }
  159.     public function setOwner(?Company $owner): self
  160.     {
  161.         $this->owner $owner;
  162.         return $this;
  163.     }
  164. }