src/Entity/Order.php line 20
<?php
namespace App\Entity;
use App\Entity\enums\OrderStatus;
use Symfony\Component\Uid\Ulid;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\OrderRepository;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
use Gedmo\Mapping\Annotation as Gedmo;
#[ORM\Entity(repositoryClass: OrderRepository::class)]
#[Gedmo\SoftDeleteable(fieldName: 'deletedAt', timeAware: false, hardDelete: true)]
#[ORM\Table(name: '`order`')]
#[ORM\HasLifecycleCallbacks]
// #[ApiResource(
// attributes: ["security" => "is_granted('ROLE_SUPER_ADMIN')"],
// )]
class Order
{
use Timestamps;
#[ORM\Id]
#[ORM\Column(type: 'ulid', unique: true)]
#[ORM\GeneratedValue(strategy: "CUSTOM")]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
private ?Ulid $id = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $name;
#[ORM\Column(type: 'integer')]
private $price = 0;
#[ORM\Column(type: 'integer')]
private $quantity = 1;
#[ORM\Column(type: 'integer')]
private $total = 0;
#[ORM\Column(type: 'string', length: 255, enumType: OrderStatus::class)]
private $status;
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'orders')]
#[ORM\JoinColumn(nullable: false)]
private $customer;
#[ORM\ManyToOne(targetEntity: Product::class, inversedBy: 'orders')]
#[ORM\JoinColumn(nullable: false)]
private $product;
#[ORM\ManyToOne(targetEntity: Coupon::class, inversedBy: 'orders')]
private $coupon;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $recipe;
#[ORM\Column(type: 'boolean')]
private $isPayed;
#[ORM\ManyToOne(targetEntity: Company::class, inversedBy: 'orders')]
#[ORM\JoinColumn(nullable: false)]
private $owner;
public function __construct()
{
$this->status = OrderStatus::DRAFT;
$this->isPayed = false;
}
public function getId(): ?Ulid
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getPrice(): ?int
{
return $this->price;
}
public function setPrice(int $price): self
{
$this->price = $price;
return $this;
}
public function getQuantity(): ?int
{
return $this->quantity;
}
public function setQuantity(int $quantity): self
{
$this->quantity = $quantity;
return $this;
}
public function getTotal(): ?int
{
return $this->total;
}
public function setTotal(int $total): self
{
$this->total = $total;
return $this;
}
public function getTotToPayal(): ?int
{
if ($this->coupon) {
return $this->total - ($this->total * $this->coupon->getAmount() / 100);
}
return $this->total;
}
public function getStatus(): ?OrderStatus
{
return $this->status;
}
public function setStatus(OrderStatus $status): self
{
$this->status = $status;
return $this;
}
public function getCustomer(): ?User
{
return $this->customer;
}
public function setCustomer(?User $customer): self
{
$this->customer = $customer;
return $this;
}
public function getProduct(): ?Product
{
return $this->product;
}
public function setProduct(?Product $product): self
{
$this->product = $product;
return $this;
}
public function getCoupon(): ?Coupon
{
return $this->coupon;
}
public function setCoupon(?Coupon $coupon): self
{
$this->coupon = $coupon;
return $this;
}
public function getRecipe(): ?string
{
return $this->recipe;
}
public function setRecipe(?string $recipe): self
{
$this->recipe = $recipe;
return $this;
}
public function isIsPayed(): ?bool
{
return $this->isPayed;
}
public function setIsPayed(bool $isPayed): self
{
$this->isPayed = $isPayed;
return $this;
}
public function getOwner(): ?Company
{
return $this->owner;
}
public function setOwner(?Company $owner): self
{
$this->owner = $owner;
return $this;
}
}