src/Entity/Order.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\OrderRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=OrderRepository::class)
  9.  * @ORM\Table(name="`order`")
  10.  */
  11. class Order
  12. {
  13.     const STATUS_NEW 0;
  14.     const STATUS_RESERVED 10;
  15.     const STATUS_PAID 1;
  16.     const STATUS_FAIL 2;
  17.     const STATUS_REFUND 3;
  18.     const STATUS_PARTIAL_REFUND 4;
  19.     const STATUS_PAYING 5;
  20.     const STATUS_WITHDRAWAL 6;
  21.     const STATUS_COMPLETE 7;
  22.     /**
  23.      * @ORM\Id
  24.      * @ORM\GeneratedValue
  25.      * @ORM\Column(type="integer")
  26.      */
  27.     private $id;
  28.     /**
  29.      * @ORM\Column(type="string", length=255, unique=true)
  30.      */
  31.     private $number;
  32.     /**
  33.      * @ORM\Column(type="datetime")
  34.      */
  35.     private $date;
  36.     /**
  37.      * @ORM\Column(type="string", length=255)
  38.      */
  39.     private $email;
  40.     /**
  41.      * @ORM\Column(type="integer")
  42.      */
  43.     private $price 0;
  44.     /**
  45.      * @ORM\Column(type="integer")
  46.      */
  47.     private $discount 0;
  48.     /**
  49.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="orders")
  50.      */
  51.     private $user;
  52.     /**
  53.      * @ORM\OneToMany(targetEntity=OrderConsultation::class, mappedBy="parent", orphanRemoval=true, cascade={"persist", "remove"})
  54.      */
  55.     private $consultations;
  56.     /**
  57.      * @ORM\Column(type="integer")
  58.      */
  59.     private $status;
  60.     /**
  61.      * @ORM\Column(type="text", nullable=true)
  62.      */
  63.     private $discountInfo;
  64.     /**
  65.      * @ORM\Column(type="json", nullable=true)
  66.      */
  67.     private $paymentInfo;
  68.     /**
  69.      * @ORM\OneToMany(targetEntity=OrderCourse::class, mappedBy="parent", orphanRemoval=true, cascade={"persist", "remove"})
  70.      */
  71.     private $courses;
  72.     /**
  73.      * @ORM\Column(type="string", length=255)
  74.      */
  75.     private $timeZone '';
  76.     /**
  77.      * @ORM\Column(type="datetime", nullable=true)
  78.      */
  79.     private $dueDate;
  80.     /**
  81.      * @ORM\Column(type="boolean")
  82.      */
  83.     private $needsRefund false;
  84.     /**
  85.      * @ORM\Column(type="json", nullable=true)
  86.      */
  87.     private $paymentErr;
  88.     /**
  89.      * @ORM\OneToMany(targetEntity=OrderService::class, mappedBy="parent", orphanRemoval=true, cascade={"persist", "remove"})
  90.      */
  91.     private $services;
  92.     /**
  93.      * @ORM\OneToMany(targetEntity=OrderPremium::class, mappedBy="parent", orphanRemoval=true, cascade={"persist", "remove"})
  94.      */
  95.     private $premiums;
  96.     public function __construct()
  97.     {
  98.         $this->status self::STATUS_NEW;
  99.         $this->consultations = new ArrayCollection();
  100.         $this->courses = new ArrayCollection();
  101.         $this->services = new ArrayCollection();
  102.         $this->premiums = new ArrayCollection();
  103.     }
  104.     public function getId(): ?int
  105.     {
  106.         return $this->id;
  107.     }
  108.     public function getDate(): ?\DateTimeInterface
  109.     {
  110.         return $this->date;
  111.     }
  112.     public function setDate(\DateTimeInterface $date): self
  113.     {
  114.         $this->date $date;
  115.         return $this;
  116.     }
  117.     public function getEmail(): ?string
  118.     {
  119.         return $this->email;
  120.     }
  121.     public function setEmail(string $email): self
  122.     {
  123.         $this->email $email;
  124.         return $this;
  125.     }
  126.     public function getPrice(): ?int
  127.     {
  128.         return $this->price;
  129.     }
  130.     public function setPrice(int $price): self
  131.     {
  132.         $this->price $price;
  133.         return $this;
  134.     }
  135.     public function getDiscount(): ?int
  136.     {
  137.         return $this->discount;
  138.     }
  139.     public function setDiscount(int $discount): self
  140.     {
  141.         $this->discount $discount;
  142.         return $this;
  143.     }
  144.     public function getUser(): ?User
  145.     {
  146.         return $this->user;
  147.     }
  148.     public function setUser(?User $user): self
  149.     {
  150.         $this->user $user;
  151.         return $this;
  152.     }
  153.     /**
  154.      * @return Collection|OrderConsultation[]
  155.      */
  156.     public function getConsultations(): Collection
  157.     {
  158.         return $this->consultations;
  159.     }
  160.     public function addConsultation(OrderConsultation $consultation): self
  161.     {
  162.         if (!$this->consultations->contains($consultation)) {
  163.             $this->consultations[] = $consultation;
  164.             $consultation->setParent($this);
  165.             $this->setPrice($this->getPrice() + $consultation->getPrice());
  166.             $this->setDiscount($this->getDiscount() + $consultation->getDiscount());
  167.         }
  168.         return $this;
  169.     }
  170.     public function removeConsultation(OrderConsultation $consultation): self
  171.     {
  172.         if ($this->consultations->removeElement($consultation)) {
  173.             // set the owning side to null (unless already changed)
  174.             if ($consultation->getParent() === $this) {
  175.                 $consultation->setParent(null);
  176.                 $this->setPrice($this->getPrice() - $consultation->getPrice());
  177.                 $this->setDiscount($this->getDiscount() - $consultation->getDiscount());
  178.             }
  179.         }
  180.         return $this;
  181.     }
  182.     public function getNumber(): ?string
  183.     {
  184.         return $this->number;
  185.     }
  186.     public function setNumber(string $number): self
  187.     {
  188.         $this->number $number;
  189.         return $this;
  190.     }
  191.     public function getStatus(): ?int
  192.     {
  193.         return $this->status;
  194.     }
  195.     public function setStatus(int $status): self
  196.     {
  197.         $this->status $status;
  198.         return $this;
  199.     }
  200.     public function getDiscountInfo(): ?string
  201.     {
  202.         return $this->discountInfo;
  203.     }
  204.     public function setDiscountInfo(?string $discountInfo): self
  205.     {
  206.         $this->discountInfo $discountInfo;
  207.         return $this;
  208.     }
  209.     public function getPaymentInfo(): ?array
  210.     {
  211.         return $this->paymentInfo;
  212.     }
  213.     public function getPaymentTransactionId(): ?string
  214.     {
  215.         return $this->paymentInfo['TransactionId'];
  216.     }
  217.     public function getPaymentInfoName(): string
  218.     {
  219.         return $this->paymentInfo['CardHolder'] ?? '';
  220.     }
  221.     public function getPaymentInfoCard(): string
  222.     {
  223.         $cardInfo = [];
  224.         if ($this->paymentInfo !== null) {
  225.             if ($this->paymentInfo['Brand'] !== null) {
  226.                 $cardInfo[] = $this->paymentInfo['Brand'];
  227.             }
  228.             if ($this->paymentInfo['CardMasked'] !== null) {
  229.                 $cardInfo[] = $this->paymentInfo['CardMasked'];
  230.             }
  231.         }
  232.         return join(' '$cardInfo);
  233.     }
  234.     public function setPaymentInfo(?array $paymentInfo): self
  235.     {
  236.         $this->paymentInfo $paymentInfo;
  237.         return $this;
  238.     }
  239.     public function getPaymentErr(): ?array
  240.     {
  241.         return $this->paymentErr;
  242.     }
  243.     public function setPaymentErr(?array $paymentErr): self
  244.     {
  245.         $this->paymentErr $paymentErr;
  246.         return $this;
  247.     }
  248.     /**
  249.      * @return Collection|OrderCourse[]
  250.      */
  251.     public function getCourses(): Collection
  252.     {
  253.         return $this->courses;
  254.     }
  255.     public function addCourse(OrderCourse $course): self
  256.     {
  257.         if (!$this->courses->contains($course)) {
  258.             $this->courses[] = $course;
  259.             $course->setParent($this);
  260.             $this->setPrice($this->getPrice() + $course->getPrice());
  261.             $this->setDiscount($this->getDiscount() + $course->getDiscount());
  262.         }
  263.         return $this;
  264.     }
  265.     public function removeCourse(OrderCourse $course): self
  266.     {
  267.         if ($this->courses->removeElement($course)) {
  268.             // set the owning side to null (unless already changed)
  269.             if ($course->getParent() === $this) {
  270.                 $course->setParent(null);
  271.                 $this->setPrice($this->getPrice() - $course->getPrice());
  272.                 $this->setDiscount($this->getDiscount() - $course->getDiscount());
  273.             }
  274.         }
  275.         return $this;
  276.     }
  277.     public function getTimeZone(): ?string
  278.     {
  279.         return $this->timeZone;
  280.     }
  281.     public function setTimeZone(string $timeZone): self
  282.     {
  283.         $this->timeZone $timeZone;
  284.         return $this;
  285.     }
  286.     public function setDueDate(\DateTimeInterface $dueDate): self
  287.     {
  288.         $this->dueDate $dueDate;
  289.         return $this;
  290.     }
  291.     public function getDueDate(): ?\DateTimeInterface
  292.     {
  293.         return $this->dueDate;
  294.     }
  295.     public function getNeedsRefund(): ?bool
  296.     {
  297.         return $this->needsRefund;
  298.     }
  299.     public function setNeedsRefund(bool $needsRefund): self
  300.     {
  301.         $this->needsRefund $needsRefund;
  302.         return $this;
  303.     }
  304.     /**
  305.      * @return Collection<int, OrderService>
  306.      */
  307.     public function getServices(): Collection
  308.     {
  309.         return $this->services;
  310.     }
  311.     public function addService(OrderService $service): self
  312.     {
  313.         if (!$this->services->contains($service)) {
  314.             $this->services[] = $service;
  315.             $service->setParent($this);
  316.             $this->setPrice($this->getPrice() + $service->getPrice());
  317.         }
  318.         return $this;
  319.     }
  320.     public function removeService(OrderService $service): self
  321.     {
  322.         if ($this->services->removeElement($service)) {
  323.             // set the owning side to null (unless already changed)
  324.             if ($service->getParent() === $this) {
  325.                 $service->setParent(null);
  326.             }
  327.         }
  328.         return $this;
  329.     }
  330.     /**
  331.      * @return Collection<int, OrderPremium>
  332.      */
  333.     public function getPremiums(): Collection
  334.     {
  335.         return $this->premiums;
  336.     }
  337.     public function addPremium(OrderPremium $premium): self
  338.     {
  339.         if (!$this->premiums->contains($premium)) {
  340.             $this->premiums[] = $premium;
  341.             $premium->setParent($this);
  342.             $this->setPrice($this->getPrice() + $premium->getPrice());
  343.         }
  344.         return $this;
  345.     }
  346.     public function removePremium(OrderPremium $premium): self
  347.     {
  348.         if ($this->premiums->removeElement($premium)) {
  349.             // set the owning side to null (unless already changed)
  350.             if ($premium->getParent() === $this) {
  351.                 $premium->setParent(null);
  352.             }
  353.         }
  354.         return $this;
  355.     }
  356. }