<?php
namespace App\Entity\Main;
use App\Entity\Main\BookedActivity;
use App\Entity\Customer\Customer;
use App\Service\CustomerService;
use App\Repository\ReservationRepository;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\EntityManager;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Persistence\ManagerRegistry;
use App\Service\Tools;
/**
* @ORM\Entity(repositoryClass=ReservationRepository::class)
*/
class Reservation
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="integer", nullable=false)
*/
private $customer_id;
/**
* @var Customer
*/
private $customer;
/**
* @ORM\Column(type="string", length=14, nullable=true)
*/
private $customerNumber;
/**
* @ORM\Column(type="string", length=64)
*/
private $formule;
/**
* @ORM\Column(type="string", length=64, nullable=true)
*/
private $formuleCode;
/**
* @ORM\Column(type="string", length=255)
*/
private $firstname;
/**
* @ORM\Column(type="string", length=255)
*/
private $lastname;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $company;
/**
* @ORM\Column(type="string", length=255)
*/
private $email;
/**
* @ORM\Column(type="string", length=32, nullable=true)
*/
private $phone;
/**
* @ORM\Column(type="string", length=32, nullable=true)
*/
private $phoneMobile;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $billingAddress;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $comment;
/**
* @ORM\Column(type="datetime")
*/
private $dateAdd;
/**
* @ORM\Column(type="datetime")
*/
private $dateResa;
/**
* @ORM\Column(type="string", length=12, nullable=true)
*/
private $numeroResa;
/**
* @ORM\Column(type="string", length=12, nullable=true)
*/
private $invoiceNumber;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $sstotalHT;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $TVA;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $totalTTC;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $history;
/**
* @ORM\Column(type="datetime")
*/
private $dateUpd;
/**
* @ORM\Column(type="string", length=128, nullable=true)
*/
private $statut;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $active;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $confirmation;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $deleted;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $composted;
/**
* @ORM\Column(type="string", length=20, nullable=true)
*/
private $ip;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $payment_id;
/**
* @var bookedActivity[]
*
* @ORM\OneToMany(targetEntity="App\Entity\Main\BookedActivity", mappedBy="reservation", cascade={"persist","remove"})
*/
private $bookedActivity;
/**
* @var reservationDetails[]
*
* @ORM\OneToMany(targetEntity="App\Entity\Main\ReservationDetails", mappedBy="reservation", cascade={"persist","remove"})
*/
private $reservationDetails;
/**
* @var historyResa[]
*
* @ORM\OneToMany(targetEntity="App\Entity\Main\History", mappedBy="reservation", cascade={"persist","remove"})
*/
private $historyResa;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $childName;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $childBirthday;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $childAge;
private $paye;
private $restedu;
protected $em;
private $cs;
private $doctrine;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $birthday_customer_comment;
public function __toString()
{
return (string) $this->numeroResa;
}
/**
* Constructor
*/
public function __construct()
{
$dateTimeZone = new \DateTimeZone('Europe/Paris');
$this->dateAdd = new \DateTime('now', $dateTimeZone);
$this->dateUpd = new \DateTime('now', $dateTimeZone);
$this->bookedActivity = new ArrayCollection();
$this->historyResa = new ArrayCollection();
$this->numeroResa = $this->generateReference();
// $this->cs = new CustomerService;
// $this->em = $entityManager;
// $doctrine = new ManagerRegistry();
// $this->em = $doctrine->getManager('customer');
// $this->customer = $this->em->getRepository(Customer::class)->find($this->getCustomerId());
// $this->setCustomer($this->getCustomerId());
}
public function getId(): ?int
{
return $this->id;
}
public function getCustomerId()
{
return $this->customer_id;
}
public function setCustomerId(?int $customer_id): self
{
$this->customer_id = $customer_id;
return $this;
}
public function getCustomer()
{
return $this->customer;
}
public function setCustomer(?Customer $customer): self
{
$this->customer = $customer;
return $this;
}
public function getCustomerNumber(): ?string
{
return $this->customerNumber;
}
public function setCustomerNumber(?string $customerNumber): self
{
$this->customerNumber = $customerNumber;
return $this;
}
public function getFormule(): ?string
{
return $this->formule;
}
public function setFormule(string $formule): self
{
$this->formule = $formule;
return $this;
}
public function getFormuleCode(): ?string
{
return $this->formuleCode;
}
public function setFormuleCode(?string $formuleCode): self
{
$this->formuleCode = $formuleCode;
return $this;
}
public function getFirstname(): ?string
{
return $this->firstname;
}
public function setFirstname(string $firstname): self
{
$this->firstname = $firstname;
return $this;
}
public function getLastname(): ?string
{
return $this->lastname;
}
public function setLastname(string $lastname): self
{
$this->lastname = $lastname;
return $this;
}
public function getCompany(): ?string
{
return $this->company;
}
public function setCompany(?string $company): self
{
$this->company = $company;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getPhoneMobile(): ?string
{
return $this->phoneMobile;
}
public function setPhoneMobile(?string $phoneMobile): self
{
$this->phoneMobile = $phoneMobile;
return $this;
}
public function getBillingAddress(): ?string
{
return $this->billingAddress;
}
public function setBillingAddress(?string $billingAddress): self
{
$this->billingAddress = $billingAddress;
return $this;
}
public function getComment(): ?string
{
return $this->comment;
}
public function setComment(?string $comment): self
{
$this->comment = $comment;
return $this;
}
public function getDateAdd(): ?\DateTimeInterface
{
return $this->dateAdd;
}
public function setDateAdd(\DateTimeInterface $dateAdd): self
{
$this->dateAdd = $dateAdd;
return $this;
}
public function getDateResa(): ?\DateTimeInterface
{
return $this->dateResa;
}
public function setDateResa(\DateTimeInterface $dateResa): self
{
$this->dateResa = $dateResa;
return $this;
}
public function getNumeroResa(): ?string
{
return $this->numeroResa;
}
public function setNumeroResa(?string $numeroResa): self
{
$this->numeroResa = $numeroResa;
return $this;
}
public function getInvoiceNumber(): ?string
{
return $this->invoiceNumber;
}
public function setInvoiceNumber(?string $invoiceNumber): self
{
$this->invoiceNumber = $invoiceNumber;
return $this;
}
public function getSstotalHT(): ?float
{
return $this->sstotalHT;
}
public function setSstotalHT(?float $sstotalHT): self
{
$this->sstotalHT = $sstotalHT;
return $this;
}
public function getTVA(): ?float
{
return $this->TVA;
}
public function setTVA(?float $TVA): self
{
$this->TVA = $TVA;
return $this;
}
public function getTotalTTC(): ?float
{
return $this->totalTTC;
}
public function setTotalTTC(?float $totalTTC): self
{
$this->totalTTC = $totalTTC;
return $this;
}
public function getHistory(): ?string
{
return $this->history;
}
public function setHistory(?string $history): self
{
$this->history = $history;
return $this;
}
public function getDateUpd(): ?\DateTimeInterface
{
return $this->dateUpd;
}
public function setDateUpd(\DateTimeInterface $dateUpd): self
{
$this->dateUpd = $dateUpd;
return $this;
}
public function getStatut(): ?string
{
return $this->statut;
}
public function setStatut(?string $statut): self
{
$this->statut = $statut;
return $this;
}
public function getActive(): ?bool
{
return $this->active;
}
public function setActive(?bool $active): self
{
$this->active = $active;
return $this;
}
public function getConfirmation(): ?bool
{
return $this->confirmation;
}
public function setConfirmation(?bool $confirmation): self
{
$this->confirmation = $confirmation;
return $this;
}
public function getDeleted(): ?bool
{
return $this->deleted;
}
public function setDeleted(?bool $deleted): self
{
$this->deleted = $deleted;
return $this;
}
public function getComposted(): ?bool
{
return $this->composted;
}
public function setComposted(?bool $composted): self
{
$this->composted = $composted;
return $this;
}
public function getChildName(): ?string
{
return $this->childName;
}
public function setChildName(?string $childName): self
{
$this->childName = $childName;
return $this;
}
public function getChildBirthday(): ?string
{
return $this->childBirthday;
}
public function setChildBirthday(string $childBirthday): self
{
$this->childBirthday = $childBirthday;
return $this;
}
public function getChildAge(): ?string
{
return $this->childAge;
}
public function setChildAge(?string $childAge): self
{
$this->childAge = $childAge;
return $this;
}
public function getIp(): ?string
{
return $this->ip;
}
public function setIp(?string $ip): self
{
$this->ip = $ip;
return $this;
}
public function getPaymentId(): ?string
{
return $this->payment_id;
}
public function setPaymentId(?string $payment_id): self
{
$this->payment_id = $payment_id;
return $this;
}
/**
* @param bookedActivity[] $bookedActivity
*/
public function setBookedActivity($bookedActivity)
{
$this->bookedActivity = $bookedActivity;
}
/**
* @return bookedActivity[]
*/
public function getBookedActivity()
{
return $this->bookedActivity;
}
/**
* @param reservationDetails[] $reservationDetails
*/
public function setReservationDetails($reservationDetails)
{
$this->reservationDetails = $reservationDetails;
}
/**
* @return reservationDetails[]
*/
public function getReservationDetails()
{
return $this->reservationDetails;
}
/**
* @param historyResa[] $historyResa
*/
public function setHistoryResa($historyResa)
{
$this->historyResa = $historyResa;
}
/**
* @return bookedActivity[]
*/
public function getHistoryResa()
{
return $this->historyResa;
}
/**
* Generate a unique reference for orders generated
* @return String
*/
public function generateReference()
{
return strtoupper(Tools::passwdGen(6, 'NO_NUMERIC'));
}
public function getSolde() {
$customer = $this->getCustomer();
if ($customer instanceof Customer) {
return $customer->getSolde();
} else {
return 0;
}
}
public function getBirthday() {
$customer = $this->getCustomer();
if ($customer instanceof Customer) {
return $customer->getBirthday();
} else {
$dateTimeZone = new \DateTimeZone('Europe/Paris');
return new \DateTime('01-01-1901', $dateTimeZone);
}
}
public function getPaye() {
$this->paye = 0;
foreach($this->historyResa as $history)
{
if( preg_match('/^Paiement/', $history->getInformation()) ) $this->paye += $history->getMouvement();
}
// return (float) number_format($this->paye, 2, '.', ' ') . ' €';
return (float) number_format($this->paye, 2, '.', ' ');
}
public function getRestedu() {
$this->restedu = 0;
foreach($this->historyResa as $history)
{
$this->restedu += $history->getMouvement();
}
$this->restedu = round($this->restedu, 2);
// return (float) number_format($this->restedu, 2, '.', ' ') . ' €';
return (float) number_format($this->restedu, 2, '.', ' ');
}
public function getBirthdayCustomerComment(): ?string
{
return $this->birthday_customer_comment;
}
public function setBirthdayCustomerComment(?string $birthday_customer_comment): self
{
$this->birthday_customer_comment = $birthday_customer_comment;
return $this;
}
}