558 lines
12 KiB
PHP
558 lines
12 KiB
PHP
<?php
|
|
|
|
namespace AppBundle\Entity;
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
/**
|
|
* TravelPeriodPrice
|
|
*
|
|
* @ORM\Table(name="travel_period_price", uniqueConstraints={@ORM\UniqueConstraint(name="UK_price_type_period_id", columns={"price_type", "period_id"})}, indexes={@ORM\Index(name="FK_travel_period_price_travel_period", columns={"period_id"})})
|
|
* @ORM\Entity
|
|
*/
|
|
class TravelPeriodPrice
|
|
{
|
|
|
|
/**
|
|
* @var float
|
|
*
|
|
* @ORM\Column(name="price_children", type="float", precision=10, scale=2, nullable=true)
|
|
*/
|
|
private $priceChildren;
|
|
|
|
/**
|
|
* @var float
|
|
*
|
|
* @ORM\Column(name="price_net", type="float", precision=10, scale=2, nullable=false)
|
|
*/
|
|
private $price = '0.00';
|
|
|
|
/**
|
|
* @var float
|
|
*
|
|
* @ORM\Column(name="price_comfort_net", type="float", precision=10, scale=2, nullable=false)
|
|
*/
|
|
private $priceComfort = '0.00';
|
|
|
|
|
|
/**
|
|
* @var float
|
|
*
|
|
* @ORM\Column(name="extra_price_children", type="float", precision=10, scale=2, nullable=true)
|
|
*/
|
|
private $extraPriceChildren;
|
|
|
|
/**
|
|
* @var float
|
|
*
|
|
* @ORM\Column(name="extra_price_net", type="float", precision=10, scale=2, nullable=false)
|
|
*/
|
|
private $extraPrice = '0.00';
|
|
|
|
/**
|
|
* @var float
|
|
*
|
|
* @ORM\Column(name="extra_price_comfort_net", type="float", precision=10, scale=2, nullable=false)
|
|
*/
|
|
private $extraPriceComfort = '0.00';
|
|
|
|
/**
|
|
* @var integer
|
|
*
|
|
* @ORM\Column(name="id", type="integer")
|
|
* @ORM\Id
|
|
* @ORM\GeneratedValue(strategy="IDENTITY")
|
|
*/
|
|
private $id;
|
|
|
|
/**
|
|
* @var \AppBundle\Entity\TravelPeriod
|
|
*
|
|
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\TravelPeriod", inversedBy="prices")
|
|
* @ORM\JoinColumns({
|
|
* @ORM\JoinColumn(name="period_id", referencedColumnName="id")
|
|
* })
|
|
*/
|
|
private $period;
|
|
|
|
/**
|
|
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\TravelPeriodPriceType")
|
|
* @ORM\JoinColumns({
|
|
* @ORM\JoinColumn(name="price_type", referencedColumnName="id")
|
|
* })
|
|
*/
|
|
private $priceType;
|
|
|
|
/**
|
|
* @ORM\Column(type="integer", nullable=false, name="price_type")
|
|
*/
|
|
private $priceTypeId;
|
|
|
|
private $effectivePrice = null;
|
|
private $effectiveChildPrice = null;
|
|
private $effectiveComfortPrice = null;
|
|
|
|
private $effectiveExtraPrice = null;
|
|
private $effectiveExtraChildPrice = null;
|
|
private $effectiveExtraComfortPrice = null;
|
|
|
|
/**
|
|
* @ORM\Column(name="available", type="integer", nullable=false)
|
|
*/
|
|
private $available;
|
|
|
|
/**
|
|
* Set priceType
|
|
*
|
|
* @param integer $priceType
|
|
*
|
|
* @return TravelPeriodPrice
|
|
*/
|
|
public function setPriceType($priceType)
|
|
{
|
|
$this->priceType = $priceType;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Get priceType
|
|
*
|
|
* @return integer
|
|
*/
|
|
public function getPriceType()
|
|
{
|
|
return $this->priceType;
|
|
}
|
|
|
|
/**
|
|
* Set available
|
|
*
|
|
* @param integer $available
|
|
*
|
|
* @return TravelPeriodPrice
|
|
*/
|
|
public function setAvailable($available)
|
|
{
|
|
$this->available = $available;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Get available
|
|
*
|
|
* @return integer
|
|
*/
|
|
public function getAvailable()
|
|
{
|
|
return $this->available;
|
|
}
|
|
|
|
/**
|
|
* Set priceChildren
|
|
*
|
|
* @param float $priceChildren
|
|
*
|
|
* @return TravelPeriodPrice
|
|
*/
|
|
public function setPriceChildren($priceChildren)
|
|
{
|
|
$this->priceChildren = $priceChildren;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Get priceChildren
|
|
*
|
|
* @return float
|
|
*/
|
|
public function getPriceChildren()
|
|
{
|
|
return $this->priceChildren;
|
|
}
|
|
|
|
/**
|
|
* Set price
|
|
*
|
|
* @param float $price
|
|
*
|
|
* @return TravelPeriodPrice
|
|
*/
|
|
public function setPrice($price)
|
|
{
|
|
$this->price = $price;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Get price
|
|
*
|
|
* @return float
|
|
*/
|
|
public function getPrice()
|
|
{
|
|
return $this->price;
|
|
}
|
|
|
|
/**
|
|
* Set priceComfort
|
|
*
|
|
* @param float $priceComfort
|
|
*
|
|
* @return TravelPeriodPrice
|
|
*/
|
|
public function setPriceComfort($priceComfort)
|
|
{
|
|
$this->priceComfort = $priceComfort;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Get priceComfort
|
|
*
|
|
* @return float
|
|
*/
|
|
public function getPriceComfort()
|
|
{
|
|
return $this->priceComfort;
|
|
}
|
|
|
|
|
|
/**
|
|
* Set extraPriceChildren
|
|
*
|
|
* @param float $extraPriceChildren
|
|
*
|
|
* @return TravelPeriodPrice
|
|
*/
|
|
public function setExtraPriceChildren($extraPriceChildren)
|
|
{
|
|
$this->extraPriceChildren = $extraPriceChildren;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Get extraPriceChildren
|
|
*
|
|
* @return float
|
|
*/
|
|
public function getExtraPriceChildren()
|
|
{
|
|
return $this->extraPriceChildren;
|
|
}
|
|
|
|
/**
|
|
* Set extraPrice
|
|
*
|
|
* @param float $extraPrice
|
|
*
|
|
* @return TravelPeriodPrice
|
|
*/
|
|
public function setExtraPrice($extraPrice)
|
|
{
|
|
$this->extraPrice = $extraPrice;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Get extraPrice
|
|
*
|
|
* @return float
|
|
*/
|
|
public function getExtraPrice()
|
|
{
|
|
return $this->extraPrice;
|
|
}
|
|
|
|
/**
|
|
* Set extraPriceComfort
|
|
*
|
|
* @param float $extraPriceComfort
|
|
*
|
|
* @return TravelPeriodPrice
|
|
*/
|
|
public function setExtraPriceComfort($extraPriceComfort)
|
|
{
|
|
$this->extraPriceComfort = $extraPriceComfort;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Get extraPriceComfort
|
|
*
|
|
* @return float
|
|
*/
|
|
public function getExtraPriceComfort()
|
|
{
|
|
return $this->extraPriceComfort;
|
|
}
|
|
|
|
|
|
/**
|
|
* Get id
|
|
*
|
|
* @return integer
|
|
*/
|
|
public function getId()
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
/**
|
|
* Set period
|
|
*
|
|
* @param \AppBundle\Entity\TravelPeriod $period
|
|
*
|
|
* @return TravelPeriodPrice
|
|
*/
|
|
public function setPeriod(\AppBundle\Entity\TravelPeriod $period = null)
|
|
{
|
|
$this->period = $period;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Get period
|
|
*
|
|
* @return \AppBundle\Entity\TravelPeriod
|
|
*/
|
|
public function getPeriod()
|
|
{
|
|
return $this->period;
|
|
}
|
|
|
|
/**
|
|
* Set priceTypeId
|
|
*
|
|
* @param integer $priceTypeId
|
|
*
|
|
* @return TravelPeriodPrice
|
|
*/
|
|
public function setPriceTypeId($priceTypeId)
|
|
{
|
|
$this->priceTypeId = $priceTypeId;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Get priceTypeId
|
|
*
|
|
* @return integer
|
|
*/
|
|
public function getPriceTypeId()
|
|
{
|
|
return $this->priceTypeId;
|
|
}
|
|
|
|
/**
|
|
* @return float
|
|
* @throws \Exception
|
|
*/
|
|
public function getEffectivePrice()
|
|
{
|
|
if ($this->effectivePrice === null)
|
|
{
|
|
throw new \Exception('Effective price must be set from outside before reading it.');
|
|
}
|
|
return $this->effectivePrice;
|
|
}
|
|
|
|
/**
|
|
* @param float $effectivePrice
|
|
*/
|
|
public function setEffectivePrice($effectivePrice)
|
|
{
|
|
$this->effectivePrice = $effectivePrice;
|
|
}
|
|
|
|
|
|
/**
|
|
* @return float
|
|
* @throws \Exception
|
|
*/
|
|
public function getEffectiveExtraPrice()
|
|
{
|
|
if ($this->effectiveExtraPrice === null)
|
|
{
|
|
throw new \Exception('EffectiveExtra price must be set from outside before reading it.');
|
|
}
|
|
return $this->effectiveExtraPrice;
|
|
}
|
|
|
|
/**
|
|
* @param float $effectiveExtraPrice
|
|
*/
|
|
public function setEffectiveExtraPrice($effectiveExtraPrice)
|
|
{
|
|
$this->effectiveExtraPrice = $effectiveExtraPrice;
|
|
}
|
|
|
|
|
|
/**
|
|
* Probably getEffectiveDiscountPrice() is the method you are actually looking for.
|
|
* @return float|null
|
|
*/
|
|
public function getDiscountPrice()
|
|
{
|
|
return $this->calculateDiscountPrice($this->price);
|
|
}
|
|
|
|
|
|
/**
|
|
* Probably getEffectiveDiscountPrice() is the method you are actually looking for.
|
|
* @return float|null
|
|
*/
|
|
public function getChildDiscountPrice()
|
|
{
|
|
return $this->calculateDiscountPrice($this->priceChildren);
|
|
}
|
|
|
|
/**
|
|
* @return float
|
|
* @throws \Exception
|
|
*/
|
|
public function getEffectiveDiscountPrice()
|
|
{
|
|
if ($this->effectivePrice === null)
|
|
{
|
|
throw new \Exception('Effective price must be set from outside before reading effective discount price.');
|
|
}
|
|
return $this->calculateDiscountPrice($this->effectivePrice);
|
|
}
|
|
|
|
/**
|
|
* @return float
|
|
* @throws \Exception
|
|
*/
|
|
public function getEffectiveChildDiscountPrice()
|
|
{
|
|
if ($this->effectiveChildPrice === null)
|
|
{
|
|
throw new \Exception('Effective price must be set from outside before reading effective discount price.');
|
|
}
|
|
return $this->calculateDiscountPrice($this->effectiveChildPrice);
|
|
}
|
|
|
|
/**
|
|
* @return float
|
|
* @throws \Exception
|
|
*
|
|
* @todo The child price will not be set yet. This is just a preparation for later
|
|
*/
|
|
public function getEffectiveChildPrice()
|
|
{
|
|
if ($this->effectiveChildPrice === null)
|
|
{
|
|
throw new \Exception('Effective child price must be set from outside before reading it.');
|
|
}
|
|
return $this->effectiveChildPrice;
|
|
}
|
|
|
|
/**
|
|
* @param null $effectiveChildPrice
|
|
*/
|
|
public function setEffectiveChildPrice($effectiveChildPrice)
|
|
{
|
|
$this->effectiveChildPrice = $effectiveChildPrice;
|
|
}
|
|
|
|
|
|
/**
|
|
* @return float
|
|
* @throws \Exception
|
|
*
|
|
* @todo The child price will not be set yet. This is just a preparation for later
|
|
*/
|
|
public function getEffectiveExtraChildPrice()
|
|
{
|
|
if ($this->effectiveExtraChildPrice === null)
|
|
{
|
|
throw new \Exception('Effective Extra child price must be set from outside before reading it.');
|
|
}
|
|
return $this->effectiveExtraChildPrice;
|
|
}
|
|
|
|
/**
|
|
* @param null $effectiveChildPrice
|
|
*/
|
|
public function setEffectiveExtraChildPrice($effectiveExtraChildPrice)
|
|
{
|
|
$this->effectiveExtraChildPrice = $effectiveExtraChildPrice;
|
|
}
|
|
|
|
|
|
/**
|
|
* @return float|null
|
|
* @throws \Exception
|
|
*/
|
|
public function getEffectiveComfortPrice()
|
|
{
|
|
if ($this->effectiveComfortPrice === null)
|
|
{
|
|
throw new \Exception('Effective comfort price must be set from outside before reading it.');
|
|
}
|
|
return $this->effectiveComfortPrice;
|
|
}
|
|
|
|
/**
|
|
* @param float|null $effectiveComfortPrice
|
|
*/
|
|
public function setEffectiveComfortPrice($effectiveComfortPrice)
|
|
{
|
|
$this->effectiveComfortPrice = $effectiveComfortPrice;
|
|
}
|
|
|
|
/**
|
|
* @return float|null
|
|
* @throws \Exception
|
|
*/
|
|
public function getEffectiveExtraComfortPrice()
|
|
{
|
|
if ($this->effectiveExtraComfortPrice === null)
|
|
{
|
|
throw new \Exception('Effective Extra comfort price must be set from outside before reading it.');
|
|
}
|
|
return $this->effectiveExtraComfortPrice;
|
|
}
|
|
|
|
/**
|
|
* @param float|null $effectiveExtraComfortPrice
|
|
*/
|
|
public function setEffectiveExtraComfortPrice($effectiveExtraComfortPrice)
|
|
{
|
|
$this->effectiveExtraComfortPrice = $effectiveExtraComfortPrice;
|
|
}
|
|
|
|
|
|
private function calculateDiscountPrice($price)
|
|
{
|
|
if ($this->getPeriod() == null)
|
|
{
|
|
return null;
|
|
}
|
|
$newPrice = $price;
|
|
foreach ($this->getPeriod()->getDiscounts() as $discount)
|
|
{
|
|
$newPrice -= $discount->getPercent()
|
|
? round($newPrice * $discount->getValue() / 100, 2) // #TODO FIXME
|
|
: $discount->getValue();
|
|
}
|
|
$program = $this->getPeriod()->getProgram();
|
|
if ($program != null && $program->getDiscount() != null)
|
|
{
|
|
$newPrice -= $program->getDiscountIsPercentValue()
|
|
? round($price * $program->getDiscount() / 100, 2) // #TODO FIXME
|
|
: $program->getDiscount();
|
|
}
|
|
return $price == $newPrice ? null : $newPrice;
|
|
}
|
|
}
|