<?php
namespace App\Entity;
use App\Repository\CommandeRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\EntityManagerInterface;
#[ORM\Entity(repositoryClass: CommandeRepository::class)]
class Commande
{
public const STATUS_ARRAY = [
'En cours' => 'En cours',
'Valide' => 'Valide'
];
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(type: Types::DATE_MUTABLE)]
private ?\DateTimeInterface $date = null;
#[ORM\Column(length: 255)]
private ?string $etat = 'En cours';
#[ORM\Column]
private ?float $totalPrice = null;
#[ORM\Column(type: Types::TEXT)]
private ?string $motifs = null;
#[ORM\Column(length: 255)]
private ?string $email;
#[ORM\Column(length: 255)]
private ?string $tel;
#[ORM\Column(length: 255)]
private ?string $adresse;
#[ORM\OneToMany(mappedBy: 'Commande', targetEntity: CommandArticle::class, cascade: ['persist', 'remove'])]
private $commandes;
#[ORM\ManyToOne(inversedBy: 'commande', targetEntity: User::class, cascade: ['persist'])]
private ?User $user = null;
#[ORM\ManyToOne(inversedBy: 'commande', targetEntity: Gouvernorat::class, cascade: ['persist'])]
private $gouvernorat;
#[ORM\Column(length: 255, nullable: true)]
private ?string $adresse_UNITE = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $CODE_POSTAL_UNITE = null;
public function getAdresseUNITE(): ?string
{
return $this->adresse_UNITE;
}
public function setAdresseUNITE(?string $adresse_UNITE): void
{
$this->adresse_UNITE = $adresse_UNITE;
}
public function getCODEPOSTALUNITE(): ?string
{
return $this->CODE_POSTAL_UNITE;
}
public function setCODEPOSTALUNITE(?string $CODE_POSTAL_UNITE): void
{
$this->CODE_POSTAL_UNITE = $CODE_POSTAL_UNITE;
}
public function __construct()
{
$this->commandes = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getMotifs(): ?string
{
return $this->motifs;
}
public function setMotifs(?string $motifs): self
{
$this->motifs = $motifs;
return $this;
}
public function getDate(): ?\DateTimeInterface
{
return $this->date;
}
public function setDate(\DateTimeInterface $date): self
{
$this->date = $date;
return $this;
}
public function getEtat(): ?string
{
return $this->etat;
}
public function setEtat(string $etat): self
{
$this->etat = $etat;
return $this;
}
public function getTel(): ?string
{
return $this->tel;
}
public function setTel(string $tel): self
{
$this->tel = $tel;
return $this;
}
public function getAdresse(): ?string
{
return $this->adresse;
}
public function setAdresse(string $adresse): self
{
$this->adresse = $adresse;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getTotalPrice(): ?float
{
return $this->totalPrice;
}
public function setTotalPrice(float $totalPrice): self
{
$this->totalPrice = $totalPrice;
return $this;
}
/**
* @return Collection<int, CommandArticle>
*/
public function getCommandes(): Collection
{
return $this->commandes;
}
public function addCommande(CommandArticle $commade): ?self
{
if (!$this->commandes->contains($commade)) {
$this->commandes->add($commade);
$commade->setCommande($this);
}
return $this;
}
public function removeCommnade(CommandArticle $commande): self
{
if ($this->commandes->removeElement($commande)) {
// set the owning side to null (unless already changed)
if ($commande->getCommande() === $this) {
$commande->setCommande(null);
}
}
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function removeCommande(CommandArticle $commande): self
{
if ($this->commandes->removeElement($commande)) {
// set the owning side to null (unless already changed)
if ($commande->getCommande() === $this) {
$commande->setCommande(null);
}
}
return $this;
}
public function getExportData()
{
$result="";
$donnees = $this->getCommandes();
foreach ($donnees as $key => $obj) {
$result = $result.'article:'.$obj->getArticle()->getTitre()." x ".$obj->getQuantite()."\n";
}
return \array_merge([
'id' => $this->getId(),
'Date' => $this->getDate()->format('d/m/Y'),
'Etat' => $this->getEtat(),
'totalPrice' => $this->getTotalPrice(),
// 'motifs' => $this->getMotifs() ?? '',
'email' => $this->getEmail() ?? '',
'tel' => $this->getTel() ?? '',
'Liste des articles' => $result,
]);
}
public function getGouvernorat(): ?Gouvernorat
{
return $this->gouvernorat;
}
public function setGouvernorat(?Gouvernorat $gouvernorat): self
{
$this->gouvernorat = $gouvernorat;
return $this;
}
}