<?php
namespace App\Entity;
use App\Repository\OrderRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: OrderRepository::class)]
#[ORM\Table(name: '`order`')]
#[ORM\HasLifecycleCallbacks]
class Order
{
public const STATUS_OPEN = 'abierto';
public const STATUS_CLOSE = 'finalizado';
public const STATUS_CANCELLED = 'cancelado';
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 255)]
private string $name;
#[ORM\Column(type: 'string', length: 255)]
private string $surename;
#[ORM\Column(type: 'string', length: 255)]
private string $email;
#[ORM\Column(type: 'string', length: 15)]
private string $phone;
#[ORM\Column(type: 'datetime', nullable: true)]
private ?\DateTimeInterface $pickupTime = null;
#[ORM\OneToMany(mappedBy: 'orderRelation', targetEntity: OrderProduct::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
private Collection $orderProducts;
#[ORM\Column(type: 'datetime')]
private \DateTimeInterface $createdAt;
#[ORM\Column(type: 'float')]
private float $total;
#[ORM\Column(type: 'float')]
private float $shipping_price = 0;
#[ORM\Column(type: 'float')]
private float $final_total;
#[ORM\Column(type: 'string', length: 15)]
private string $status;
#[ORM\Column(type: 'string', length: 255)]
private string $address;
#[ORM\Column(type: 'string', length: 50)]
private string $number;
#[ORM\Column(type: 'string', length: 50, nullable: true)]
private ?string $door = null;
#[ORM\Column(type: 'string', length: 20)]
private string $postalCode;
#[ORM\Column(type: 'string', length: 100)]
private string $city;
#[ORM\Column(type: 'string', length: 100)]
private string $province;
#[ORM\Column(type: 'string', length: 20, unique: true, nullable: true)]
private ?string $trackingId = null;
#[ORM\OneToOne(mappedBy: 'order', targetEntity: Payment::class, cascade: ['persist', 'remove'])]
private ?Payment $payment = null;
#[ORM\OneToOne(mappedBy: 'order', targetEntity: Shipping::class, cascade: ['persist', 'remove'])]
private ?Shipping $shipping = null;
#[ORM\OneToOne(mappedBy: 'order', targetEntity: Invoice::class, cascade: ['persist', 'remove'])]
private ?Invoice $invoice = null;
public function __construct()
{
$this->orderProducts = new ArrayCollection();
}
public function __toString(): string
{
return (string) $this->getId();
}
public function setCreatedAt(\DateTimeInterface $createdAt = new \DateTime()): void
{
$this->createdAt = $createdAt;
}
public function getCreatedAt(): \DateTimeInterface
{
return $this->createdAt;
}
public function getId(): ?int { return $this->id; }
public function getName(): ?string { return $this->name; }
public function setName(string $name): self { $this->name = $name; return $this; }
public function getSurename(): ?string { return $this->surename; }
public function setSurename(string $surename): self { $this->surename = $surename; return $this; }
public function getEmail(): ?string { return $this->email; }
public function setEmail(string $email): self { $this->email = $email; return $this; }
public function getPhone(): ?string { return $this->phone; }
public function setPhone(string $phone): self { $this->phone = $phone; return $this; }
public function getPickupTime(): ?\DateTimeInterface { return $this->pickupTime; }
public function setPickupTime(\DateTimeInterface $pickupTime): self { $this->pickupTime = $pickupTime; return $this; }
public function getOrderProducts(): Collection { return $this->orderProducts; }
public function addOrderProduct(OrderProduct $orderProduct): self
{
if (!$this->orderProducts->contains($orderProduct)) {
$this->orderProducts[] = $orderProduct;
$orderProduct->setOrderRelation($this);
}
return $this;
}
public function removeOrderProduct(OrderProduct $orderProduct): self
{
if ($this->orderProducts->removeElement($orderProduct)) {
if ($orderProduct->getOrderRelation() === $this) {
$orderProduct->setOrderRelation(null);
}
}
return $this;
}
public function removeOrderProducts(): self
{
foreach($this->getOrderProducts() as $orderProduct){
$this->removeOrderProduct($orderProduct);
}
return $this;
}
public function getTotal(): ?float { return $this->total; }
public function setTotal(float $total): self { $this->total = $total; return $this; }
public function getShippingPrice(): ?float { return $this->shipping_price; }
public function setShippingPrice(float $shipping_price): self { $this->shipping_price = $shipping_price; return $this; }
public function getFinalTotal(): ?float { return $this->final_total ?? $this->total + $this->shipping_price ; }
public function setFinalTotal(float $final_total): self { $this->final_total = $final_total; return $this; }
public function getStatus(): ?string { return $this->status; }
public function setStatus(string $status): self { $this->status = $status; return $this; }
public function getAddress(): ?string { return $this->address; }
public function setAddress(string $address): self { $this->address = $address; return $this; }
public function getNumber(): ?string { return $this->number; }
public function setNumber(string $number): self { $this->number = $number; return $this; }
public function getDoor(): ?string { return $this->door; }
public function setDoor(?string $door): self { $this->door = $door; return $this; }
public function getPostalCode(): ?string { return $this->postalCode; }
public function setPostalCode(string $postalCode): self { $this->postalCode = $postalCode; return $this; }
public function getCity(): ?string { return $this->city; }
public function setCity(string $city): self { $this->city = $city; return $this; }
public function getProvince(): ?string { return $this->province; }
public function setProvince(string $province): self { $this->province = $province; return $this; }
public function getTrackingId(): ?string { return $this->trackingId; }
public function setTrackingId(string $trackingId): self { $this->trackingId = $trackingId; return $this; }
public function getPayment(): ?Payment { return $this->payment; }
public function setPayment(?Payment $payment): self { $this->payment = $payment; return $this; }
public function getShipping(): ?Shipping { return $this->shipping; }
public function setShipping(?Shipping $shipping): self { $this->shipping = $shipping; return $this; }
public function getInvoice(): ?Invoice { return $this->invoice; }
public function setInvoice(?Invoice $invoice): self { $this->invoice = $invoice; return $this; }
public function getPaymentStatus(): string
{
return $this->payment ? $this->payment->getStatus() : 'no hay pago';
}
public function getShippingStatus(): string
{
return $this->shipping ? $this->shipping->getStatus() : 'no hay envio';
}
}