src/Entity/Order.php line 15

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\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * @ORM\Entity(repositoryClass=OrderRepository::class)
  10.  * @ORM\Table(name="`order`")
  11.  */
  12. class Order
  13. {
  14.     /**
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     private $id;
  20.     /**
  21.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="orders")
  22.      */
  23.     private $user;
  24.     /**
  25.      * @ORM\ManyToOne(targetEntity=Shop::class, inversedBy="orders")
  26.      */
  27.     private $shop;
  28.     /**
  29.      * @ORM\OneToMany(targetEntity=Cart::class, mappedBy="order")
  30.      */
  31.     private $carts;
  32.     /**
  33.      * @ORM\Column(type="string", length=64, nullable=true)
  34.      */
  35.     private $reference;
  36.     /**
  37.      * @ORM\Column(type="string", length=32, nullable=true)
  38.      */
  39.     private $coupon;
  40.     /**
  41.      * @ORM\Column(type="string", length=255, nullable=true)
  42.      */
  43.     private $customReference;
  44.     /**
  45.      * @ORM\ManyToOne(targetEntity=Address::class, cascade={"persist"})
  46.      */
  47.     private $deliveryAddress;
  48.     /**
  49.      * @ORM\ManyToOne(targetEntity=Address::class, cascade={"persist"})
  50.      */
  51.     private $invoiceAddress;
  52.     /**
  53.      * @ORM\Column(type="boolean", nullable=true)
  54.      */
  55.     private $confirm;
  56.     /**
  57.      * @ORM\Column(type="boolean", nullable=true)
  58.      */
  59.     private $acceptTerms;
  60.     /**
  61.      * @ORM\Column(type="integer", nullable=true)
  62.      */
  63.     private $totalProduct;
  64.     /**
  65.      * @ORM\Column(type="integer", nullable=true)
  66.      */
  67.     private $deliveryHt;
  68.     /**
  69.      * @ORM\Column(type="integer", nullable=true)
  70.      */
  71.     private $deliveryTotal;
  72.     /**
  73.      * @ORM\Column(type="integer", nullable=true)
  74.      */
  75.     private $amountHt;
  76.     /**
  77.      * @ORM\Column(type="integer", nullable=true)
  78.      */
  79.     private $amountTotal;
  80.     /**
  81.      * @ORM\Column(type="integer", nullable=true)
  82.      */
  83.     private $discount;
  84.     /**
  85.      * @ORM\Column(type="decimal", precision=4, scale=2, nullable=true)
  86.      */
  87.     private $vat;
  88.     /**
  89.      * @ORM\Column(type="datetime", nullable=true)
  90.      */
  91.     private $date;
  92.     /**
  93.      * @ORM\Column(type="integer", nullable=true)
  94.      */
  95.     private $b2lId;
  96.     /**
  97.      * @ORM\Column(type="string", length=128, nullable=true)
  98.      */
  99.     private $bak2Reference;
  100.     /**
  101.      * @ORM\Column(type="string", length=128, nullable=true)
  102.      */
  103.     private $shippingNumber;
  104.     /**
  105.      * @ORM\ManyToOne(targetEntity=Status::class, inversedBy="orders")
  106.      */
  107.     private $status;
  108.     /**
  109.      * @ORM\OneToOne(targetEntity=Imei::class, mappedBy="order", cascade={"persist", "remove"})
  110.      */
  111.     private $imeis;
  112.     /**
  113.      * @ORM\OneToOne(targetEntity=Address::class, cascade={"persist", "remove"})
  114.      */
  115.     private $tempAddress;
  116.     /**
  117.      * @ORM\Column(type="string", length=16, nullable=true)
  118.      */
  119.     private $payment;
  120.     /**
  121.      * @ORM\Column(type="string", length=32, nullable=true)
  122.      */
  123.     private $paymentReference;
  124.     /**
  125.      * @ORM\Column(type="text", nullable=true)
  126.      */
  127.     private $comment;
  128.     /**
  129.      * @ORM\ManyToMany(targetEntity=Option::class, mappedBy="order", cascade={"persist"})
  130.      */
  131.     private $options;
  132.     /**
  133.      * @ORM\Column(type="integer", nullable=true)
  134.      */
  135.     private $optionPrice;
  136.     /**
  137.      * @ORM\Column(type="string", nullable=true)
  138.      */
  139.     private $invoiceFilename;
  140.     /**
  141.      * @ORM\Column(type="boolean", nullable=true)
  142.      */
  143.     private $active;
  144.     /**
  145.      * @ORM\OneToMany(targetEntity=Sav::class, mappedBy="order")
  146.      */
  147.     private $savs;
  148.     private $displayName;
  149.     public function __construct()
  150.     {
  151.         $this->carts = new ArrayCollection();
  152.         $this->status = new ArrayCollection();
  153.         $this->options = new ArrayCollection();
  154.         $this->savs = new ArrayCollection();
  155.     }
  156.     public function __toString() {
  157.         return $this->getReference();
  158.     }
  159.     public function getId(): ?int
  160.     {
  161.         return $this->id;
  162.     }
  163.     public function getUser(): ?User
  164.     {
  165.         return $this->user;
  166.     }
  167.     public function setUser(?User $user): self
  168.     {
  169.         $this->user $user;
  170.         return $this;
  171.     }
  172.     public function getShop(): ?Shop
  173.     {
  174.         if($this->shop==null) {
  175.             $this->shop=$this->getUser()->getShop();
  176.         }
  177.         return $this->shop;
  178.     }
  179.     public function setShop(?Shop $shop): self
  180.     {
  181.         $this->shop $shop;
  182.         return $this;
  183.     }
  184.     /**
  185.      * @return Collection<int, Cart>
  186.      */
  187.     public function getCarts(): Collection
  188.     {
  189.         return $this->carts;
  190.     }
  191.     public function addCart(Cart $cart): self
  192.     {
  193.         if (!$this->carts->contains($cart)) {
  194.             $this->carts[] = $cart;
  195.             $cart->setOrder($this);
  196.         }
  197.         return $this;
  198.     }
  199.     public function removeCart(Cart $cart): self
  200.     {
  201.         if ($this->carts->removeElement($cart)) {
  202.             // set the owning side to null (unless already changed)
  203.             if ($cart->getOrder() === $this) {
  204.                 $cart->setOrder(null);
  205.             }
  206.         }
  207.         return $this;
  208.     }
  209.     public function nbProducts() {
  210.         $carts=$this->getCarts();
  211.         $qty=0;
  212.         foreach($carts as $cart) {
  213.             $qty+=$cart->getQty();
  214.         }
  215.         return $qty;
  216.     }
  217.     public function totalAmount() {
  218.         $carts=$this->getCarts();
  219.         $total=0;
  220.         foreach($carts as $cart) {
  221.             $total+=($cart->getQty() * $cart->getPrice());
  222.         }
  223.         return $total/100;
  224.     }
  225.     public function getReference(): ?string
  226.     {
  227.         return $this->reference;
  228.     }
  229.     public function setReference(string $reference): self
  230.     {
  231.         $this->reference $reference;
  232.         return $this;
  233.     }
  234.     public function getCustomReference(): ?string
  235.     {
  236.         return $this->customReference;
  237.     }
  238.     public function setCustomReference(string $customReference): self
  239.     {
  240.         $this->customReference $customReference;
  241.         return $this;
  242.     }
  243.     public function getDeliveryAddress(): ?Address
  244.     {
  245.         return $this->deliveryAddress;
  246.     }
  247.     public function setDeliveryAddress(?Address $deliveryAddress): self
  248.     {
  249.         $this->deliveryAddress $deliveryAddress;
  250.         return $this;
  251.     }
  252.     public function getInvoiceAddress(): ?Address
  253.     {
  254.         return $this->invoiceAddress;
  255.     }
  256.     public function setInvoiceAddress(?Address $invoiceAddress): self
  257.     {
  258.         $this->invoiceAddress $invoiceAddress;
  259.         return $this;
  260.     }
  261.     public function getConfirm(): ?bool
  262.     {
  263.         return $this->confirm;
  264.     }
  265.     public function setConfirm(?bool $confirm): self
  266.     {
  267.         $this->confirm $confirm;
  268.         return $this;
  269.     }
  270.     public function getAcceptTerms(): ?bool
  271.     {
  272.         return $this->acceptTerms;
  273.     }
  274.     public function setAcceptTerms(?bool $acceptTerms): self
  275.     {
  276.         $this->acceptTerms $acceptTerms;
  277.         return $this;
  278.     }
  279.     public function getTotalProduct(): ?int
  280.     {
  281.         return $this->totalProduct;
  282.     }
  283.     public function setTotalProduct(?int $totalProduct): self
  284.     {
  285.         $this->totalProduct $totalProduct;
  286.         return $this;
  287.     }
  288.     public function getDeliveryHt(): ?int
  289.     {
  290.         return $this->deliveryHt;
  291.     }
  292.     public function setDeliveryHt(?int $deliveryHt): self
  293.     {
  294.         $this->deliveryHt $deliveryHt;
  295.         return $this;
  296.     }
  297.     public function getDeliveryTotal(): ?int
  298.     {
  299.         return $this->deliveryTotal;
  300.     }
  301.     public function setDeliveryTotal(?int $deliveryTotal): self
  302.     {
  303.         $this->deliveryTotal $deliveryTotal;
  304.         return $this;
  305.     }
  306.     public function getAmountHt(): ?int
  307.     {
  308.         return $this->amountHt;
  309.     }
  310.     public function setAmountHt(?int $amountHt): self
  311.     {
  312.         $this->amountHt $amountHt;
  313.         return $this;
  314.     }
  315.     public function getAmountTotal(): ?int
  316.     {
  317.         return $this->amountTotal;
  318.     }
  319.     public function setAmountTotal(?int $amountTotal): self
  320.     {
  321.         $this->amountTotal $amountTotal;
  322.         return $this;
  323.     }
  324.     public function getVat(): ?string
  325.     {
  326.         return $this->vat;
  327.     }
  328.     public function setVat(?string $vat): self
  329.     {
  330.         $this->vat $vat;
  331.         return $this;
  332.     }
  333.     public function getDate(): ?\DateTimeInterface
  334.     {
  335.         return $this->date;
  336.     }
  337.     public function setDate(\DateTimeInterface $date): self
  338.     {
  339.         $this->date $date;
  340.         return $this;
  341.     }
  342.     public function getB2lId(): ?int
  343.     {
  344.         return $this->b2lId;
  345.     }
  346.     public function setB2lId(?int $b2lId): self
  347.     {
  348.         $this->b2lId $b2lId;
  349.         return $this;
  350.     }
  351.     public function generateReference() {
  352.         return "B-".$this->getUser()->getId()."-".$this->getId();
  353.         /*$date=new \DateTime('now');
  354.         return 'P-'.$date->format('YmdHis')."-".rand(0,1000);
  355.         */
  356.     }
  357.     public function getBak2Reference(): ?string
  358.     {
  359.         return $this->bak2Reference;
  360.     }
  361.     public function setBak2Reference(?string $bak2Reference): self
  362.     {
  363.         $this->bak2Reference $bak2Reference;
  364.         return $this;
  365.     }
  366.     public function getShippingNumber(): ?string
  367.     {
  368.         return $this->shippingNumber;
  369.     }
  370.     public function setShippingNumber(?string $shippingNumber): self
  371.     {
  372.         $this->shippingNumber $shippingNumber;
  373.         return $this;
  374.     }
  375.     public function getStatus(): ?Status
  376.     {
  377.         return $this->status;
  378.     }
  379.     public function setStatus(?Status $status): self
  380.     {
  381.         $this->status $status;
  382.         return $this;
  383.     }
  384.     public function getImeis(): ?Imei
  385.     {
  386.         return $this->imeis;
  387.     }
  388.     public function setImeis(?Imei $imeis): self
  389.     {
  390.         // unset the owning side of the relation if necessary
  391.         if ($imeis === null && $this->imeis !== null) {
  392.             $this->imeis->setOrder(null);
  393.         }
  394.         // set the owning side of the relation if necessary
  395.         if ($imeis !== null && $imeis->getOrder() !== $this) {
  396.             $imeis->setOrder($this);
  397.         }
  398.         $this->imeis $imeis;
  399.         return $this;
  400.     }
  401.     public function getTempAddress(): ?Address
  402.     {
  403.         return $this->tempAddress;
  404.     }
  405.     public function setTempAddress(?Address $tempAddress): self
  406.     {
  407.         $this->tempAddress $tempAddress;
  408.         return $this;
  409.     }
  410.     public function getPayment(): ?string
  411.     {
  412.         return $this->payment;
  413.     }
  414.     public function setPayment(string $payment): self
  415.     {
  416.         $this->payment $payment;
  417.         return $this;
  418.     }
  419.     public function getPaymentReference(): ?string
  420.     {
  421.         return $this->paymentReference;
  422.     }
  423.     public function setPaymentReference(string $paymentReference): self
  424.     {
  425.         $this->paymentReference $paymentReference;
  426.         return $this;
  427.     }
  428.     public function getComment(): ?string
  429.     {
  430.         return $this->comment;
  431.     }
  432.     public function setComment(?string $comment): self
  433.     {
  434.         $this->comment $comment;
  435.         return $this;
  436.     }
  437.     public function isConfirm(): ?bool
  438.     {
  439.         return $this->confirm;
  440.     }
  441.     public function getCoupon(): ?string
  442.     {
  443.         return $this->coupon;
  444.     }
  445.     public function setCoupon(?string $coupon): static
  446.     {
  447.         $this->coupon $coupon;
  448.         return $this;
  449.     }
  450.     public function setDiscount($discount) {
  451.         $this->discount $discount;
  452.     }
  453.     public function getDiscount()
  454.     {
  455.         return $this->discount;
  456.     }
  457.     public function applyCoupon() {
  458.         $coupon=$this->getCoupon();
  459.         $totalAmount=$this->getAmountTotal();
  460.         if($coupon) {
  461.             switch($coupon->getType()) {
  462.                 case "percent":
  463.                 default:
  464.                     $this->setAmountTotal($totalAmount - ($totalAmount $coupon->getValue()/100));
  465.                     break;
  466.             }
  467.         }
  468.     }
  469.     public function isAcceptTerms(): ?bool
  470.     {
  471.         return $this->acceptTerms;
  472.     }
  473.     /**
  474.      * @return Collection<int, Option>
  475.      */
  476.     public function getOptions(): Collection
  477.     {
  478.         return $this->options;
  479.     }
  480.     public function addOption(Option $option): static
  481.     {
  482.         if (!$this->options->contains($option)) {
  483.             $this->options->add($option);
  484.             $option->addOrder($this);
  485.         }
  486.         return $this;
  487.     }
  488.     public function removeOption(Option $option): static
  489.     {
  490.         if ($this->options->removeElement($option)) {
  491.             $option->removeOrder($this);
  492.         }
  493.         return $this;
  494.     }
  495.     public function hasOption($option): bool
  496.     {
  497.         foreach($this->options as $o) {
  498.             if($o->getId()==$option->getId()) {
  499.                 return true;
  500.             }
  501.         }
  502.         return false;
  503.     }
  504.     public function getOptionPrice(): ?int
  505.     {
  506.         return $this->optionPrice;
  507.     }
  508.     public function setOptionPrice(?int $optionPrice): static
  509.     {
  510.         $this->optionPrice $optionPrice;
  511.         return $this;
  512.     }
  513.     public function getInvoiceFilename(): ?string
  514.     {
  515.         return $this->invoiceFilename;
  516.     }
  517.     public function setInvoiceFilename(string $invoiceFilename): self
  518.     {
  519.         $this->invoiceFilename $invoiceFilename;
  520.         return $this;
  521.     }
  522.     public function getActive():bool
  523.     {
  524.         return $this->active;
  525.     }
  526.     public function setActive(bool $active):self
  527.     {
  528.         $this->active $active;
  529.         return $this;
  530.     }
  531.     public function isActive(): ?bool
  532.     {
  533.         return $this->active;
  534.     }
  535.     public function getDisplayName() {
  536.         return $this->getReference()." - ".$this->getDate()->format('d/m/Y');//. " (".$this->getStatus().")";
  537.     }
  538.     /**
  539.      * @return Collection<int, Sav>
  540.      */
  541.     public function getSavs(): Collection
  542.     {
  543.         return $this->savs;
  544.     }
  545.     public function addSav(Sav $sav): static
  546.     {
  547.         if (!$this->savs->contains($sav)) {
  548.             $this->savs->add($sav);
  549.             $sav->setOrder($this);
  550.         }
  551.         return $this;
  552.     }
  553.     public function removeSav(Sav $sav): static
  554.     {
  555.         if ($this->savs->removeElement($sav)) {
  556.             // set the owning side to null (unless already changed)
  557.             if ($sav->getOrder() === $this) {
  558.                 $sav->setOrder(null);
  559.             }
  560.         }
  561.         return $this;
  562.     }
  563. }