<?php
namespace App\Entity;
use App\Repository\ClickAndCollectRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ClickAndCollectRepository::class)
* @ORM\EntityListeners({
* "App\Listener\EntityListener",
* "App\Listener\ClickAndCollectListener"
* })
*/
class ClickAndCollect
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="integer")
*/
private $number;
/**
* @ORM\Column(type="string", length=3)
*/
private $currency;
/**
* @ORM\Column(type="string", length=2)
*/
private $locale;
/**
* @ORM\Column(type="float")
*/
private $priceSum;
/**
* @ORM\Column(type="float")
*/
private $priceSumNoTax;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $note;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
private $clientFirstName;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
private $clientLastName;
/**
* @ORM\Column(type="string", length=190, nullable=true)
*/
private $clientEmail;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
private $clientPhone;
/**
* @ORM\Column(type="integer")
*/
private $status = 0;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $notifyts;
/**
* @ORM\Column(type="datetime")
*/
private $createts;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $editts;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User")
*/
private $editUser;
/**
* @ORM\OneToMany(targetEntity=ClickAndCollectItem::class, mappedBy="collect",cascade={"persist"})
*/
private $items;
/**
* @ORM\Column(type="boolean")
*/
private $canSend = false;
/**
* @ORM\Column(type="boolean")
*/
private $sendedEmail = false;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $sendedEmailts;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $reservedTo;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $stornots;
/**
* @ORM\Column(type="boolean")
*/
private $extended = false;
public function __construct()
{
$this->items = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getNumber(): ?int
{
return $this->number;
}
public function setNumber(int $number): self
{
$this->number = $number;
return $this;
}
public function getCurrency(): ?string
{
return $this->currency;
}
public function setCurrency(string $currency): self
{
$this->currency = $currency;
return $this;
}
public function getPriceSum(): ?float
{
return $this->priceSum;
}
public function setPriceSum(float $priceSum): self
{
$this->priceSum = $priceSum;
return $this;
}
public function getPriceSumNoTax(): ?float
{
return $this->priceSumNoTax;
}
public function setPriceSumNoTax(float $priceSumNoTax): self
{
$this->priceSumNoTax = $priceSumNoTax;
return $this;
}
public function getNote(): ?string
{
return $this->note;
}
public function setNote(?string $note): self
{
$this->note = $note;
return $this;
}
public function getClientFirstName(): ?string
{
return $this->clientFirstName;
}
public function setClientFirstName(?string $clientFirstName): self
{
$this->clientFirstName = $clientFirstName;
return $this;
}
public function getClientLastName(): ?string
{
return $this->clientLastName;
}
public function setClientLastName(?string $clientLastName): self
{
$this->clientLastName = $clientLastName;
return $this;
}
public function getClientEmail(): ?string
{
return $this->clientEmail;
}
public function setClientEmail(?string $clientEmail): self
{
$this->clientEmail = $clientEmail;
return $this;
}
public function getClientPhone(): ?string
{
return $this->clientPhone;
}
public function setClientPhone(?string $clientPhone): self
{
$this->clientPhone = $clientPhone;
return $this;
}
public function getStatus(): ?int
{
return $this->status;
}
public function setStatus(int $status): self
{
$this->status = $status;
return $this;
}
public function getNotifyts(): ?\DateTimeInterface
{
return $this->notifyts;
}
public function setNotifyts(?\DateTimeInterface $notifyts): self
{
$this->notifyts = $notifyts;
return $this;
}
public function getCreatets(): ?\DateTimeInterface
{
return $this->createts;
}
public function setCreatets(\DateTimeInterface $createts): self
{
$this->createts = $createts;
return $this;
}
public function getEditts(): ?\DateTimeInterface
{
return $this->editts;
}
public function setEditts(?\DateTimeInterface $editts): self
{
$this->editts = $editts;
return $this;
}
public function getEditUser(): ?User
{
return $this->editUser;
}
public function setEditUser(?User $editUser): self
{
$this->editUser = $editUser;
return $this;
}
public function getHash( )
{
return base64_encode(sprintf('%s|%s|%s',$this->getClientEmail(),$this->getNumber(),$this->getId()));
}
/**
* @return Collection|ClickAndCollectItem[]
*/
public function getItems(): Collection
{
return $this->items;
}
public function addItem(ClickAndCollectItem $item): self
{
if (!$this->items->contains($item)) {
$this->items[] = $item;
$item->setCollect($this);
}
return $this;
}
public function removeItem(ClickAndCollectItem $item): self
{
if ($this->items->contains($item)) {
$this->items->removeElement($item);
// set the owning side to null (unless already changed)
if ($item->getCollect() === $this) {
$item->setCollect(null);
}
}
return $this;
}
public function initClient(?Client $client): self
{
if($client instanceof Client) {
$this->setClient( $client );
$this->setClientFirstName( $client->getFirstName() );
$this->setClientLastName( $client->getLastName() );
$this->setClientEmail( $client->getEmail() );
$this->setClientPhone( $client->getPhone() );
//$this->setClientPhone( $client->get );
/*if($client->getBillingAddress() instanceof ClientAddress){
$billing = $client->getBillingAddress();
}else{
$billing = $client->getClientAddresses()->first();
}
$billingAddress = new OrderAddress();
$billingAddress->init( $billing );
$this->setBillingAddress($billingAddress);
if($client->getDeliveryAddress() instanceof ClientAddress){
$delivery = $client->getDeliveryAddress();
}else{
$delivery = $billing;
}
$deliveryAddress = new OrderAddress();
$deliveryAddress->init( $delivery );
$this->setDeliveryAddress($deliveryAddress);*/
}
return $this;
}
public function initCart( Cart $cart )
{
$this->setClient($cart->getClient());
$this->setClientPhone($cart->getPhone());
$this->setClientEmail($cart->getEmail());
$this->setClientLastName($cart->getLastName());
$this->setClientFirstName($cart->getFirstName());
$this->setNote($cart->getNote());
$this->setLocale(\Locale::getDefault());
foreach ($cart->getCartItems() as $cartItem){
$item = new ClickAndCollectItem();
$item->setCount($cartItem->getCount());
$item->setProduct($cartItem->getProduct());
$item->setVariant($cartItem->getVariant());
$item->setName(sprintf('%s - %s',$cartItem->getProduct()->getName(),$cartItem->getVariant()->getName()));
$item->setDealer($cartItem->getProduct()->getDealer());
$item->setCourse($cartItem->getProduct()->getDealer()->getCourse());
$pricelist = $cartItem->getProduct()->getPrice();
$item->setPrice($pricelist->getPrice());
$item->setTax($pricelist->getTax());
$item->setCurrency($pricelist->getCurrency());
$this->setCurrency($pricelist->getCurrency());
$this->addItem($item);
}
return $this;
}
/**
* Get CanSend
*
* @return mixed
*/
public function getCanSend()
{
return $this->canSend;
}
/**
* Set CanSend
*
* @param mixed $canSend
*/
public function setCanSend( $canSend )
{
$this->canSend = $canSend;
}
/**
* Get SendedEmail
*
* @return mixed
*/
public function getSendedEmail()
{
return $this->sendedEmail;
}
/**
* Set SendedEmail
*
* @param mixed $sendedEmail
*/
public function setSendedEmail( $sendedEmail )
{
$this->sendedEmail = $sendedEmail;
}
/**
* Get SendedEmailts
*
* @return mixed
*/
public function getSendedEmailts()
{
return $this->sendedEmailts;
}
/**
* Set SendedEmailts
*
* @param mixed $sendedEmailts
*/
public function setSendedEmailts( $sendedEmailts )
{
$this->sendedEmailts = $sendedEmailts;
}
/**
* Get ReservedTo
*
* @return mixed
*/
public function getReservedTo()
{
return $this->reservedTo;
}
/**
* Set ReservedTo
*
* @param mixed $reservedTo
*/
public function setReservedTo( $reservedTo )
{
$this->reservedTo = $reservedTo;
}
/**
* Get Extended
*
* @return mixed
*/
public function getExtended()
{
return $this->extended;
}
/**
* Set Extended
*
* @param mixed $extended
*/
public function setExtended( $extended )
{
$this->extended = $extended;
}
/**
* Get Stornots
*
* @return mixed
*/
public function getStornots()
{
return $this->stornots;
}
/**
* Set Stornots
*
* @param mixed $stornots
*/
public function setStornots( $stornots )
{
$this->stornots = $stornots;
}
/**
* Get Locale
*
* @return mixed
*/
public function getLocale()
{
return $this->locale;
}
/**
* Set Locale
*
* @param mixed $locale
*/
public function setLocale( $locale )
{
$this->locale = $locale;
}
}