<?php
namespace App\Entity;
use Stripe\PaymentIntent;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\OrderRepository;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity(repositoryClass=OrderRepository::class)
* @ORM\HasLifecycleCallbacks
* @ORM\Table(name="`order`")
*/
class Order
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="orders")
* @ORM\JoinColumn(nullable=false)
*/
private $user;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @ORM\Column(type="datetime")
*/
private $updatedAt;
/**
* @ORM\Column(type="string", length=255)
*/
private $reference;
/**
* @ORM\OneToMany(targetEntity=OrderDetails::class, mappedBy="myorder")
*/
private $orderDetails;
/**
* @ORM\ManyToOne(targetEntity=OrderStatus::class, inversedBy="orders")
*/
private $stat;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="ordersGrossistes")
* @ORM\JoinColumn(nullable=true)
*/
private $grossiste;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $dateprevision;
/**
* @ORM\ManyToOne(targetEntity=EtatPaiement::class, inversedBy="orders")
*/
private $etatpaiement;
/**
* @ORM\ManyToOne(targetEntity=Typepaiement::class, inversedBy="orders")
*/
private $typepaiement;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $stripeSessionId;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $montant_paye;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $date_last_paiement;
/**
* @ORM\OneToMany(targetEntity=HistoriquePaiement::class, mappedBy="my_order")
*/
private $historiquePaiements;
public function __construct()
{
$this->orderDetails = new ArrayCollection();
$this->createdAt = new \DateTime();
$this->historiquePaiements = new ArrayCollection();
}
/**
* Undocumented function
*
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function initialiseSlug()
{
$this->updatedAt = new \DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getReference(): ?string
{
return $this->reference;
}
public function setReference(string $reference): self
{
$this->reference = $reference;
return $this;
}
/**
* @return Collection<int, OrderDetails>
*/
public function getOrderDetails(): Collection
{
return $this->orderDetails;
}
public function addOrderDetail(OrderDetails $orderDetail): self
{
if (!$this->orderDetails->contains($orderDetail)) {
$this->orderDetails[] = $orderDetail;
$orderDetail->setMyorder($this);
}
return $this;
}
public function removeOrderDetail(OrderDetails $orderDetail): self
{
if ($this->orderDetails->removeElement($orderDetail)) {
// set the owning side to null (unless already changed)
if ($orderDetail->getMyorder() === $this) {
$orderDetail->setMyorder(null);
}
}
return $this;
}
public function getStat(): ?OrderStatus
{
return $this->stat;
}
public function setStat(?OrderStatus $stat): self
{
$this->stat = $stat;
return $this;
}
public function getGrossiste(): ?User
{
return $this->grossiste;
}
public function setGrossiste(?User $grossiste): self
{
$this->grossiste = $grossiste;
return $this;
}
public function getTotal()
{
$total = 0;
foreach($this->getOrderDetails()->getValues() as $product){
$total += $product->getTotal();
}
return $total;
}
public function getDateprevision(): ?\DateTimeInterface
{
return $this->dateprevision;
}
public function setDateprevision(?\DateTimeInterface $dateprevision): self
{
$this->dateprevision = $dateprevision;
return $this;
}
public function getEtatpaiement(): ?EtatPaiement
{
return $this->etatpaiement;
}
public function setEtatpaiement(?EtatPaiement $etatpaiement): self
{
$this->etatpaiement = $etatpaiement;
return $this;
}
public function getTypepaiement(): ?Typepaiement
{
return $this->typepaiement;
}
public function setTypepaiement(?Typepaiement $typepaiement): self
{
$this->typepaiement = $typepaiement;
return $this;
}
public function getStripeSessionId(): ?string
{
return $this->stripeSessionId;
}
public function setStripeSessionId(?string $stripeSessionId): self
{
$this->stripeSessionId = $stripeSessionId;
return $this;
}
public function getMontantPaye(): ?float
{
return $this->montant_paye;
}
public function setMontantPaye(?float $montant_paye): self
{
$this->montant_paye = $montant_paye;
return $this;
}
public function getDateLastPaiement(): ?\DateTimeInterface
{
return $this->date_last_paiement;
}
public function setDateLastPaiement(?\DateTimeInterface $date_last_paiement): self
{
$this->date_last_paiement = $date_last_paiement;
return $this;
}
/**
* @return Collection<int, HistoriquePaiement>
*/
public function getHistoriquePaiements(): Collection
{
return $this->historiquePaiements;
}
public function addHistoriquePaiement(HistoriquePaiement $historiquePaiement): self
{
if (!$this->historiquePaiements->contains($historiquePaiement)) {
$this->historiquePaiements[] = $historiquePaiement;
$historiquePaiement->setMyOrder($this);
}
return $this;
}
public function removeHistoriquePaiement(HistoriquePaiement $historiquePaiement): self
{
if ($this->historiquePaiements->removeElement($historiquePaiement)) {
// set the owning side to null (unless already changed)
if ($historiquePaiement->getMyOrder() === $this) {
$historiquePaiement->setMyOrder(null);
}
}
return $this;
}
}