<?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`")
*/
class Order
{
const STATUS_NEW = 0;
const STATUS_RESERVED = 10;
const STATUS_PAID = 1;
const STATUS_FAIL = 2;
const STATUS_REFUND = 3;
const STATUS_PARTIAL_REFUND = 4;
const STATUS_PAYING = 5;
const STATUS_WITHDRAWAL = 6;
const STATUS_COMPLETE = 7;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, unique=true)
*/
private $number;
/**
* @ORM\Column(type="datetime")
*/
private $date;
/**
* @ORM\Column(type="string", length=255)
*/
private $email;
/**
* @ORM\Column(type="integer")
*/
private $price = 0;
/**
* @ORM\Column(type="integer")
*/
private $discount = 0;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="orders")
*/
private $user;
/**
* @ORM\OneToMany(targetEntity=OrderConsultation::class, mappedBy="parent", orphanRemoval=true, cascade={"persist", "remove"})
*/
private $consultations;
/**
* @ORM\Column(type="integer")
*/
private $status;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $discountInfo;
/**
* @ORM\Column(type="json", nullable=true)
*/
private $paymentInfo;
/**
* @ORM\OneToMany(targetEntity=OrderCourse::class, mappedBy="parent", orphanRemoval=true, cascade={"persist", "remove"})
*/
private $courses;
/**
* @ORM\Column(type="string", length=255)
*/
private $timeZone = '';
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $dueDate;
/**
* @ORM\Column(type="boolean")
*/
private $needsRefund = false;
/**
* @ORM\Column(type="json", nullable=true)
*/
private $paymentErr;
/**
* @ORM\OneToMany(targetEntity=OrderService::class, mappedBy="parent", orphanRemoval=true, cascade={"persist", "remove"})
*/
private $services;
/**
* @ORM\OneToMany(targetEntity=OrderPremium::class, mappedBy="parent", orphanRemoval=true, cascade={"persist", "remove"})
*/
private $premiums;
public function __construct()
{
$this->status = self::STATUS_NEW;
$this->consultations = new ArrayCollection();
$this->courses = new ArrayCollection();
$this->services = new ArrayCollection();
$this->premiums = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getDate(): ?\DateTimeInterface
{
return $this->date;
}
public function setDate(\DateTimeInterface $date): self
{
$this->date = $date;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getPrice(): ?int
{
return $this->price;
}
public function setPrice(int $price): self
{
$this->price = $price;
return $this;
}
public function getDiscount(): ?int
{
return $this->discount;
}
public function setDiscount(int $discount): self
{
$this->discount = $discount;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
/**
* @return Collection|OrderConsultation[]
*/
public function getConsultations(): Collection
{
return $this->consultations;
}
public function addConsultation(OrderConsultation $consultation): self
{
if (!$this->consultations->contains($consultation)) {
$this->consultations[] = $consultation;
$consultation->setParent($this);
$this->setPrice($this->getPrice() + $consultation->getPrice());
$this->setDiscount($this->getDiscount() + $consultation->getDiscount());
}
return $this;
}
public function removeConsultation(OrderConsultation $consultation): self
{
if ($this->consultations->removeElement($consultation)) {
// set the owning side to null (unless already changed)
if ($consultation->getParent() === $this) {
$consultation->setParent(null);
$this->setPrice($this->getPrice() - $consultation->getPrice());
$this->setDiscount($this->getDiscount() - $consultation->getDiscount());
}
}
return $this;
}
public function getNumber(): ?string
{
return $this->number;
}
public function setNumber(string $number): self
{
$this->number = $number;
return $this;
}
public function getStatus(): ?int
{
return $this->status;
}
public function setStatus(int $status): self
{
$this->status = $status;
return $this;
}
public function getDiscountInfo(): ?string
{
return $this->discountInfo;
}
public function setDiscountInfo(?string $discountInfo): self
{
$this->discountInfo = $discountInfo;
return $this;
}
public function getPaymentInfo(): ?array
{
return $this->paymentInfo;
}
public function getPaymentTransactionId(): ?string
{
return $this->paymentInfo['TransactionId'];
}
public function getPaymentInfoName(): string
{
return $this->paymentInfo['CardHolder'] ?? '';
}
public function getPaymentInfoCard(): string
{
$cardInfo = [];
if ($this->paymentInfo !== null) {
if ($this->paymentInfo['Brand'] !== null) {
$cardInfo[] = $this->paymentInfo['Brand'];
}
if ($this->paymentInfo['CardMasked'] !== null) {
$cardInfo[] = $this->paymentInfo['CardMasked'];
}
}
return join(' ', $cardInfo);
}
public function setPaymentInfo(?array $paymentInfo): self
{
$this->paymentInfo = $paymentInfo;
return $this;
}
public function getPaymentErr(): ?array
{
return $this->paymentErr;
}
public function setPaymentErr(?array $paymentErr): self
{
$this->paymentErr = $paymentErr;
return $this;
}
/**
* @return Collection|OrderCourse[]
*/
public function getCourses(): Collection
{
return $this->courses;
}
public function addCourse(OrderCourse $course): self
{
if (!$this->courses->contains($course)) {
$this->courses[] = $course;
$course->setParent($this);
$this->setPrice($this->getPrice() + $course->getPrice());
$this->setDiscount($this->getDiscount() + $course->getDiscount());
}
return $this;
}
public function removeCourse(OrderCourse $course): self
{
if ($this->courses->removeElement($course)) {
// set the owning side to null (unless already changed)
if ($course->getParent() === $this) {
$course->setParent(null);
$this->setPrice($this->getPrice() - $course->getPrice());
$this->setDiscount($this->getDiscount() - $course->getDiscount());
}
}
return $this;
}
public function getTimeZone(): ?string
{
return $this->timeZone;
}
public function setTimeZone(string $timeZone): self
{
$this->timeZone = $timeZone;
return $this;
}
public function setDueDate(\DateTimeInterface $dueDate): self
{
$this->dueDate = $dueDate;
return $this;
}
public function getDueDate(): ?\DateTimeInterface
{
return $this->dueDate;
}
public function getNeedsRefund(): ?bool
{
return $this->needsRefund;
}
public function setNeedsRefund(bool $needsRefund): self
{
$this->needsRefund = $needsRefund;
return $this;
}
/**
* @return Collection<int, OrderService>
*/
public function getServices(): Collection
{
return $this->services;
}
public function addService(OrderService $service): self
{
if (!$this->services->contains($service)) {
$this->services[] = $service;
$service->setParent($this);
$this->setPrice($this->getPrice() + $service->getPrice());
}
return $this;
}
public function removeService(OrderService $service): self
{
if ($this->services->removeElement($service)) {
// set the owning side to null (unless already changed)
if ($service->getParent() === $this) {
$service->setParent(null);
}
}
return $this;
}
/**
* @return Collection<int, OrderPremium>
*/
public function getPremiums(): Collection
{
return $this->premiums;
}
public function addPremium(OrderPremium $premium): self
{
if (!$this->premiums->contains($premium)) {
$this->premiums[] = $premium;
$premium->setParent($this);
$this->setPrice($this->getPrice() + $premium->getPrice());
}
return $this;
}
public function removePremium(OrderPremium $premium): self
{
if ($this->premiums->removeElement($premium)) {
// set the owning side to null (unless already changed)
if ($premium->getParent() === $this) {
$premium->setParent(null);
}
}
return $this;
}
}