<?php
namespace App\Entity;
use App\Repository\CommandeRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=CommandeRepository::class)
*/
class Commande
{
const STATUT_TO_BE_DELETED = "delete";
const STATUT_BROUILLON = "brouillon";
const STATUT_COMPLETE = "complete";
const STATUT_CANCELLED = "annule";
const STATUT_PART = "part";
const STATUT_OPEN = "open";
const NBRE_INSCRIPTION_MAX = 8;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $commandeId;
/**
* @ORM\OneToMany(targetEntity=Inscription::class, mappedBy="commande", fetch="EAGER", cascade={"persist", "remove"})
*/
private $inscription;
/**
* @ORM\OneToMany(targetEntity=Compta::class, mappedBy="commande")
*/
private $compta;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $statut;
/**
* @ORM\Column(type="datetime")
*/
private $dateCreation;
/**
* @ORM\Column(type="datetime",nullable= true)
*/
private $dateReminderPaiement;
/**
* @ORM\Column(type="datetime",nullable= true)
*/
private $dateReminderDocument;
/**
* @ORM\Column(type="datetime")
*/
private $dateModification;
/**
*
* @ORM\OneToMany(targetEntity=ReductionRequest::class, mappedBy="commande", cascade={"persist", "remove"})
*/
private $reductionRequest;
/**
* @ORM\ManyToOne(targetEntity=EnterpriseOptionSejourSession::class, inversedBy="commandes", cascade={"persist", "remove"})
*/
private $enterpriseOptionSejourSession;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $commentaire;
public function __construct()
{
$this->inscription = new ArrayCollection();
$this->reductionRequest = new ArrayCollection();
$this->compta = new ArrayCollection();
$this->dateCreation = new \Datetime();
$this->dateReminderDocument = new \Datetime();
$this->dateReminderPaiement = new \Datetime();
$this->dateModification = new \Datetime();
$this->commandeId = uniqid();
}
public function getId(): ?int
{
return $this->id;
}
public function getCommandeId(): ?string
{
return $this->commandeId;
}
public function setCommandeId(string $commandeId): self
{
$this->commandeId = $commandeId;
return $this;
}
/**
* @return Collection|Inscription[]
*/
public function getInscription(): Collection
{
return $this->inscription;
}
public function addInscription(Inscription $inscription): self
{
if (!$this->inscription->contains($inscription)) {
$this->inscription[] = $inscription;
$inscription->setCommande($this);
}
return $this;
}
public function removeInscription(Inscription $inscription): self
{
if ($this->inscription->removeElement($inscription)) {
// set the owning side to null (unless already changed)
if ($inscription->getCommande() === $this) {
$inscription->setCommande(null);
}
}
return $this;
}
/**
* @return Collection|Compta[]
*/
public function getCompta(): Collection
{
return $this->compta;
}
public function addComptum(Compta $comptum): self
{
if (!$this->compta->contains($comptum)) {
$this->compta[] = $comptum;
$comptum->setCommande($this);
}
return $this;
}
public function removeComptum(Compta $comptum): self
{
if ($this->compta->removeElement($comptum)) {
// set the owning side to null (unless already changed)
if ($comptum->getCommande() === $this) {
$comptum->setCommande(null);
}
}
return $this;
}
public function getStatut(): ?string
{
return $this->statut;
}
public function setStatut(?string $statut): self
{
$this->statut = $statut;
return $this;
}
public function getDateCreation(): ?\DateTimeInterface
{
$timezone = new \DateTimeZone('Europe/Paris');
$dateCreation = $this->dateCreation;
if ($dateCreation) {
$dateCreation->setTimezone($timezone);
}
return $dateCreation;
}
public function setDateCreation(\DateTimeInterface $dateCreation): self
{
$this->dateCreation = $dateCreation;
return $this;
}
public function getDateReminderPaiement(): ?\DateTimeInterface
{
$timezone = new \DateTimeZone('Europe/Paris');
$dateReminderPaiement = $this->dateReminderPaiement;
if ($dateReminderPaiement) {
$dateReminderPaiement->setTimezone($timezone);
}
return $dateReminderPaiement;
}
public function setDateReminderPaiement(\DateTimeInterface $dateReminderPaiement): self
{
$this->dateReminderPaiement = $dateReminderPaiement;
return $this;
}
public function getDateReminderDocument(): ?\DateTimeInterface
{
$timezone = new \DateTimeZone('Europe/Paris');
$dateReminderDocument = $this->dateReminderDocument;
if ($dateReminderDocument) {
$dateReminderDocument->setTimezone($timezone);
}
return $dateReminderDocument;
}
public function setDateReminderDocument(\DateTimeInterface $dateReminderDocument): self
{
$this->dateReminderDocument = $dateReminderDocument;
return $this;
}
public function getDateModification(): ?\DateTimeInterface
{
$timezone = new \DateTimeZone('Europe/Paris');
$dateModification = $this->dateModification;
if ($dateModification) {
$dateModification->setTimezone($timezone);
}
return $dateModification;
}
public function setDateModification(\DateTimeInterface $dateModification): self
{
$this->dateModification = $dateModification;
return $this;
}
public function getPaiementOverview(): array
{
$output = ['total' => 0, 'reduction' => ['en attente' => 0, 'paid' => 0], 'payment' => ['en attente' => 0, 'paid' => 0]];
foreach ($this->compta as $compta) {
if ($compta->getComptaType() !== null) {
switch ($compta->getComptaType()->getTypeOperation()) {
case 'Cost':
if ($compta->getStatut() !== Compta::STATUT_CANCELLED)
$output['total'] += $compta->getValeur();
break;
case 'Payment':
if ($compta->getStatut() == Compta::STATUT_PART || $compta->getStatut() == Compta::STATUT_COMPLETE) {
$output['payment']['paid'] += $compta->getValeur();
break;
}
if ($compta->getStatut() == Compta::STATUT_OPEN || $compta->getStatut() == Compta::STATUT_PROMESSE) {
$output['payment']['en attente'] += $compta->getValeur();
break;
}
break;
case 'Reduction':
if ($compta->getStatut() == Compta::STATUT_PART || $compta->getStatut() == Compta::STATUT_COMPLETE) {
$output['reduction']['paid'] += $compta->getValeur();
break;
}
if ($compta->getStatut() == Compta::STATUT_OPEN || $compta->getStatut() == Compta::STATUT_PROMESSE) {
$output['reduction']['en attente'] += $compta->getValeur();
break;
}
break;
}
}
}
return $output;
}
public function getOpenInvoice(): float
{
$output = 0;
foreach ($this->compta as $compta) {
if ($compta->getStatut() !== "annulé")
$output += $compta->getValeur();
}
return $output;
}
public function getAllSolde(): float
{
$output = 0;
foreach ($this->compta as $compta) {
if ($compta->getStatut() !== "annulé" && $compta->getStatut() !== "promesse")
$output += $compta->getValeur();
}
return $output;
}
public function getTotalPrice(): float
{
$output = 0;
foreach ($this->compta as $compta) {
if ($compta->getType() !== "acompte" && $compta->getType() !== "solde")
$output += $compta->getValeur();
}
return $output;
}
public function getTotalPrice2(): float
{
$output = 0;
foreach ($this->compta as $compta) {
if ( $compta->getType() == "total"){
$output += $compta->getValeur();
}
}
return $output;
}
/**
* @return Collection|Inscription[]
*/
public function getReductionRequest(): Collection
{
return $this->reductionRequest;
}
public function addReductionRequest(ReductionRequest $inscription): self
{
if (!$this->reductionRequest->contains($inscription)) {
$this->reductionRequest[] = $inscription;
$inscription->setCommande($this);
}
return $this;
}
public function removeReductionRequest(ReductionRequest $inscription): self
{
if ($this->reductionRequest->removeElement($inscription)) {
// set the owning side to null (unless already changed)
if ($inscription->getCommande() === $this) {
$inscription->setCommande(null);
}
}
return $this;
}
private function addValueOrCreateKey(string $key, mixed $value, array $array): array
{
if (array_key_exists($key, $array)) {
$array[$key] += $value;
return $array;
}
$array[$key] = $value;
return $array;
}
public function getNombreInscription(): int
{
return count($this->inscription);
}
public function getEnterpriseOptionSejourSession(): ?EnterpriseOptionSejourSession
{
return $this->enterpriseOptionSejourSession;
}
public function setEnterpriseOptionSejourSession(?EnterpriseOptionSejourSession $enterpriseOptionSejourSession): self
{
$this->enterpriseOptionSejourSession = $enterpriseOptionSejourSession;
return $this;
}
public function getCommentaire(): ?string
{
return $this->commentaire;
}
public function setCommentaire(?string $commentaire): self
{
$this->commentaire = $commentaire;
return $this;
}
}