<?php
namespace App\Entity;
use App\Repository\DeliveryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use JsonSerializable;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=DeliveryRepository::class)
*/
class Delivery implements JsonSerializable
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $address;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $phone;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $tva;
/**
* @ORM\Column(type="float")
*/
private $price;
/**
* @ORM\Column(type="float")
*/
private $totalPrice;
/**
* @ORM\OneToMany(targetEntity=Document::class, mappedBy="delivery")
*/
private $documents;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $position;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isSelected;
/**
* @ORM\Column(type="string", length=255)
*/private $type;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $deletedAt;
public function __construct()
{
$this->documents = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getPrice(): ?float
{
return $this->price;
}
public function setPrice(float $price): self
{
$this->price = $price;
return $this;
}
public function getTotalPrice(): ?float
{
return $this->totalPrice;
}
public function setTotalPrice(float $totalPrice): self
{
$this->totalPrice = $totalPrice;
return $this;
}
/**
* @return Collection|Document[]
*/
public function getDocuments(): Collection
{
return $this->documents;
}
public function addDocument(Document $document): self
{
if( !$this->documents->contains($document)) {
$this->documents[] = $document;
$document->setDelivery($this);
}
return $this;
}
public function removeDocument(Document $document): self
{
if( $this->documents->removeElement($document)) {
// set the owning side to null (unless already changed)
if( $document->getDelivery() === $this) {
$document->setDelivery(null);
}
}
return $this;
}
public function getPosition(): ?int
{
return $this->position;
}
public function setPosition(?int $position): self
{
$this->position = $position;
return $this;
}
public function getIsSelected(): ?bool
{
return $this->isSelected;
}
public function setIsSelected(?bool $isSelected): self
{
$this->isSelected = $isSelected;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getDeletedAt(): ?\DateTimeInterface
{
return $this->deletedAt;
}
public function setDeletedAt(?\DateTimeInterface $deletedAt): self
{
$this->deletedAt = $deletedAt;
return $this;
}
public function jsonSerialize()
{
return array(
'id' => $this->getId(),
'name' => $this->getName(),
'price' => $this->getPrice(),
'amountFreeDelivery' => isset($_ENV['FREE_DELIVERY_AMOUNT']) ? floatval($_ENV['FREE_DELIVERY_AMOUNT']) : 0, // Minimum de commande pour avoir une livraison gratuite
);
}
public function setAddress(string $address): self
{
$this->address = $address;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setPhone(string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setTva(string $tva): self
{
$this->tva = $tva;
return $this;
}
public function getTva(): ?string
{
return $this->tva;
}
}