<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\DeliveryMethodRepository")
*/
class DeliveryMethod
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="integer")
*/
private $averageDays;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $firstItem;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $additionalItem;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Product", inversedBy="deliveryMethods")
*/
private $product;
/**
* @ORM\Column(type="integer")
*/
private $serviceId;
/**
* @ORM\Column(type="boolean")
*/
private $valid=false;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\CompanyDefaultShipping", inversedBy="deliveryMethods")
*/
private $companyDefaultShipping;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $freeAboveATotalOf;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $fixedPrice;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $pickupSchedule;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $pickupAddress;
/**
* @ORM\Column(type="boolean")
*/
private $isAPickup=false;
/**
* @ORM\Column(type="integer")
*/
private $pickupLocationId=false;
/**
* @ORM\Column(type="boolean")
*/
private $withPacking=false;
public function getId()
{
return $this->id;
}
public function getServiceName(){
switch($this->getServiceId()){
case 0:
return 'Poste Canada';
case 1:
return 'Purolator';
case 2:
return 'FedEx';
case 3:
return 'UPS';
case 4:
return 'Autre';
case 5:
return 'Dicom';
case 9999:
return 'Pickup';
}
}
public function getDeliveryDays(){
switch($this->getAverageDays()){
case 1:
return '1-2';
case 2:
return '2-4';
case 3:
return '5-7';
case 4:
return '7-10';
case 5:
return '10+';
case 6:
return '3-5';
}
}
public function getAverageDays(): ?int
{
return $this->averageDays;
}
public function setAverageDays(int $averageDays): self
{
$this->averageDays = $averageDays;
return $this;
}
public function getPickupLocationId(): ?int
{
return $this->pickupLocationId;
}
public function setPickupLocationId(int $pickupLocationId): self
{
$this->pickupLocationId = $pickupLocationId;
return $this;
}
public function getFirstItem(): ?float
{
return $this->firstItem;
}
public function setFirstItem(?float $firstItem): self
{
$this->firstItem = $firstItem;
return $this;
}
public function getAdditionalItem(): ?float
{
return $this->additionalItem;
}
public function setAdditionalItem(?float $additionalItem): self
{
$this->additionalItem = $additionalItem;
return $this;
}
public function getProduct(): ?Product
{
return $this->product;
}
public function setProduct(?Product $product): self
{
$this->product = $product;
return $this;
}
public function getServiceId(): ?int
{
return $this->serviceId;
}
public function setServiceId(int $serviceId): self
{
$this->serviceId = $serviceId;
return $this;
}
public function getValid(): ?bool
{
return $this->valid;
}
public function setValid(bool $valid): self
{
$this->valid = $valid;
return $this;
}
public function getCompanyDefaultShipping(): ?CompanyDefaultShipping
{
return $this->companyDefaultShipping;
}
public function setCompanyDefaultShipping(?CompanyDefaultShipping $companyDefaultShipping): self
{
$this->companyDefaultShipping = $companyDefaultShipping;
return $this;
}
public function getFreeAboveATotalOf(): ?float
{
return $this->freeAboveATotalOf;
}
public function setFreeAboveATotalOf(?float $freeAboveATotalOf): self
{
$this->freeAboveATotalOf = $freeAboveATotalOf;
return $this;
}
public function getFixedPrice(): ?float
{
return $this->fixedPrice;
}
public function setFixedPrice(?float $fixedPrice): self
{
$this->fixedPrice = $fixedPrice;
return $this;
}
public function getDisplayPrice()
{
if(is_float($this->getFixedPrice()) && $this->getFixedPrice() == 0){
if($this->getServiceId() != 9999)
return 'Gratuite en '.$this->getDeliveryDays().' Jour(s) avec le transporteur '.$this->getServiceName();
else
return "Ramassage par vous même d'ici ".$this->getDeliveryDays().' jour(s)';
}
if(!empty($this->getFreeAboveATotalOf()) && $this->getFixedPrice()){
if($this->getServiceId() != 9999){
$free = 'Gratuite avec achat minimum de '.number_format($this->getFreeAboveATotalOf(),2).'$ en '.$this->getDeliveryDays().' Jour(s) avec le transporteur '.$this->getServiceName();
}else{
$free = 'Ramassage par vous même avec achat minimum de '.number_format($this->getFreeAboveATotalOf(),2).'$ en '.$this->getDeliveryDays().' Jour(s) ';
}
if($this->getFixedPrice()){
$free = number_format($this->getFixedPrice(),2).'$ ou '.$free;
}
return $free;
}
if(!empty($this->getFreeAboveATotalOf())){
if($this->getServiceId() != 9999){
return 'Gratuite avec achat minimum de '.number_format($this->getFreeAboveATotalOf(),2).'$ en '.$this->getDeliveryDays().' Jour(s) avec le transporteur '.$this->getServiceName();
}else{
return 'Ramassage par vous même avec achat minimum de '.number_format($this->getFreeAboveATotalOf(),2).'$ en '.$this->getDeliveryDays().' Jour(s) ';
}
}
if($this->getFixedPrice() != null){
if($this->getServiceId() != 9999)
return number_format($this->getFixedPrice(),2).'$ en '.$this->getDeliveryDays().' Jour(s) avec le transporteur '.$this->getServiceName();
else
return 'Ramassage par vous même pour un prix fixe de '.number_format($this->getFixedPrice(),2)."$ d'ici ".$this->getDeliveryDays().' Jour(s)';
}
if($this->getFirstItem() != null){
$text = number_format($this->getFirstItem(),2).'$ par unité ';
if($this->getAdditionalItem() != null){
$text .= 'et '.number_format($this->getAdditionalItem(),2).'$ par unité supplémentaire';
}
$text .= 'en '.$this->getDeliveryDays().' Jour(s) avec le transporteur '.$this->getServiceName();
return $text;
}
return 'Inconnu';
}
public function __toString(){
return $this->getDisplayPrice();
}
public function getPickupSchedule(): ?string
{
return $this->pickupSchedule;
}
public function setPickupSchedule(?string $pickupSchedule): self
{
$this->pickupSchedule = $pickupSchedule;
return $this;
}
public function getPickupAddress(): ?string
{
return $this->pickupAddress;
}
public function setPickupAddress(?string $pickupAddress): self
{
$this->pickupAddress = $pickupAddress;
return $this;
}
public function getIsAPickup(): ?bool
{
return $this->isAPickup;
}
public function setIsAPickup(bool $isAPickup): self
{
$this->isAPickup = $isAPickup;
return $this;
}
public function getWithPacking(): bool {
return $this->withPacking;
}
public function setWithPacking(bool $withPacking): self {
$this->withPacking = $withPacking;
return $this;
}
}