<?php
namespace App\Entity\Otpusk;
use Doctrine\ORM\EntityNotFoundException;
use Doctrine\ORM\Mapping as ORM;
use Twig\Error\RuntimeError;
/**
* @ORM\Entity(repositoryClass="App\Repository\Otpusk\PriceIndexRepository")
*
* @ORM\Table(
* name="priceIndex",
* indexes={
* @ORM\Index(name="id", columns={"rec_id", "price", "offerId"}),
* @ORM\Index(name="best", columns={"best"}),
* @ORM\Index(name="id_date", columns={"rec_id", "date"}),
* @ORM\Index(name="type_price", columns={"type", "price"}),
* @ORM\Index(name="countryId", columns={"countryId", "date"}),
* @ORM\Index(name="cityId", columns={"cityId", "date"}),
* @ORM\Index(name="offerId", columns={"offerId"}),
* @ORM\Index(name="rec_id", columns={"rec_id", "type", "from"}),
* @ORM\Index(name="transport", columns={"rec_id", "fromCityId", "transport"}),
* @ORM\Index(name="operatorId", columns={"operatorId", "countryId", "date"}),
* @ORM\Index(name="vrein_testible_combined_1", columns={"countryId", "price", "date", "transport", "fromCityId", "priceUah"}),
* @ORM\Index(name="vrein_testible_combined_2", columns={"cityId", "rec_id", "date"})
* },
* )
*/
class PriceIndex
{
/**
* @var int
*
* @ORM\Column(name="num", type="integer", nullable=false, options={"unsigned"=true})
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $num;
/**
* @ORM\Column (name="rec_id", type="integer", options={"unsigned":true, "comment":"Страна-Курорт-Отель"}, nullable=false)
*/
private $idCostil;
//@ORM\JoinColumn(name="rec_id", referencedColumnName="id", columnDefinition="INT UNSIGNED NOT NULL COMMENT 'Страна-Курорт-Отель'")
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Otpusk\HotelsRCache")
* @ORM\JoinColumn(name="rec_id", referencedColumnName="id")
*/
private $id;
/**
* Virtual field to connect priceIndex with tHotels
* @ORM\ManyToOne(targetEntity="App\Entity\Otpusk\Hotel", inversedBy="priceIndex")
* @ORM\JoinColumn(name="rec_id", referencedColumnName="rec_id")
*/
private $hotel;
/**
* @ORM\Column(name="type", type="priceIndexType", nullable=false, options={"default"="hotel"})
*/
private $type;
/**
* @ORM\Column (name="countryId", type="integer", options={"unsigned":true}, nullable=false)
*/
private $countryCostil;
//@ORM\JoinColumn(name="countryId", referencedColumnName="rec_id", nullable=false, columnDefinition="INT UNSIGNED NOT NULL")
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Otpusk\Country", cascade={"persist"})
* @ORM\JoinColumn(name="countryId", referencedColumnName="rec_id", nullable=false)
*/
private $country;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Otpusk\City", inversedBy="priceIndex", cascade={"persist"})
* @ORM\JoinColumn(name="cityId", referencedColumnName="rec_id", nullable=false, columnDefinition="INT UNSIGNED NOT NULL")
*/
private $city;
// /**
// * @ORM\Id()
// * @ORM\GeneratedValue(strategy="NONE")
// * @ORM\Column(name="offerId")
// */
// private $offerId;
/**
* @var string
*
* @ORM\Column(name="offerId", type="string", length=25, nullable=false, options={"comment"="номер цены"})
*/
private $offerId;
/**
* @ORM\Column(name="from", type="smallint", nullable=false, options={"unsigned"=true,"comment"="страна отправления"})
*/
private $fromCountry;
/**
* @ORM\Column(type="decimal", precision=14, scale=2, nullable=false, options={"comment"="минимальная, с длительностью 6-10"})
*/
private $price;
/**
* @ORM\Column(type="string", type="priceIndexCurrency")
*/
private $currency;
/**
* @ORM\Column(type="decimal", precision=12, scale=2, nullable=false, options={"comment"="цена в грн. по курсу оператора"})
*/
private $priceUah;
/**
* @ORM\Column(type="decimal", precision=12, scale=2, nullable=false, options={"comment"="цена в usd по курсу оператора"})
*/
private $priceUsd;
/**
* @ORM\Column(type="decimal", precision=12, scale=2, nullable=false, options={"comment"="цена в eur по курсу оператора"})
*/
private $priceEur;
/**
* @ORM\Column(type="decimal", precision=12, scale=2, nullable=false, options={"comment"="цена в mdl по курсу оператора"})
*/
private $priceMdl;
/**
* @ORM\Column(type="decimal", precision=12, scale=2, nullable=false, options={"comment"="цена в uzs по курсу оператора"})
*/
private $priceUzs;
/**
* @ORM\Column(type="decimal", precision=12, scale=2, nullable=false, options={"comment"="цена в pln по курсу оператора"})
*/
private $pricePln;
/**
* @ORM\Column(type="date", nullable=false, options={"comment"="дата цены"})
*/
private $date;
/**
* @ORM\Column(type="integer", nullable=false, options={"comment"="минимальная длительность !=0"})
*/
private $length;
/**
* @ORM\Column(type="string", length=8, nullable=false, options={"comment"="необходим для установления приоритетов по цене"})
*/
private $transport;
/**
* @ORM\Column(type="string", length=3, nullable=false, options={"comment"="питание"})
*/
private $food;
/**
* @ORM\Column(type="string", length=32, nullable=false, options={"comment"="номер"})
*/
private $room;
/**
* @ORM\Column(name="best", type="integer", nullable=true, options={"comment"="Лучшая-цена качество"})
*/
private $best;
/**
* @ORM\Column(type="datetime", nullable=false, options={"comment"="дата последнего обновления"})
*/
private $last;
/**
* @ORM\Column (name="fromCityId", type="integer", options={"unsigned":true,"default":1544,"comment":"город отправления"}, nullable=false)
*/
private $fromCityCostil;
//@ORM\JoinColumn(name="fromCityId", referencedColumnName="rec_id", nullable=false, columnDefinition="INT UNSIGNED DEFAULT 1544 NOT NULL COMMENT 'город отправления'")
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Otpusk\City", cascade={"persist"})
* @ORM\JoinColumn(name="fromCityId", referencedColumnName="rec_id", nullable=false)
*/
private $fromCity;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Otpusk\ExchangeRate", cascade={"persist"})
* @ORM\JoinColumn(name="currency", referencedColumnName="id")
*/
private $exchange;
/**
* @var int
*
* @ORM\Column(name="operatorId", type="integer", nullable=false, options={"unsigned"=true})
*/
private $operatorid;
/**
* @var string
*
* @ORM\Column(name="inf", type="text", length=65535, nullable=true, options={"comment"="формула"})
*/
private $inf;
/**
* @ORM\Column(type="decimal", precision=12, scale=2, nullable=false, options={"comment"="цена в kzt по курсу оператора"})
*/
private $priceKzt;
/**
* @ORM\Column(type="decimal", precision=12, scale=2, nullable=false, options={"comment"="цена в czk по курсу оператора"})
*/
private $priceCzk;
/**
* @ORM\Column(type="decimal", precision=12, scale=2, nullable=false, options={"comment"="цена в huf по курсу оператора"})
*/
private $priceHuf;
public function __toString()
{
return 'Предложение ' . $this->getOfferId();
}
public function getId()
{
try{
return $this->id;
} catch (EntityNotFoundException $e){
return '';
} catch (RuntimeError $e){
return '';
}
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getCountry(): ?Country
{
return $this->country;
}
public function setCountry(?Country $country): self
{
$this->country = $country;
return $this;
}
public function getCity(): ?City
{
return $this->city;
}
public function setCity(?City $city): self
{
$this->city = $city;
return $this;
}
public function getOfferId(): ?int
{
return $this->offerId;
}
public function setOfferId(int $offerId): self
{
$this->offerId = $offerId;
return $this;
}
public function getFromCountry(): ?Country
{
return $this->fromCountry;
}
public function setFromCountry(?Country $fromCountry): self
{
$this->fromCountry = $fromCountry;
return $this;
}
public function getPrice(): ?float
{
return $this->price;
}
public function setPrice(float $price): self
{
$this->price = $price;
return $this;
}
public function getCurrency(): ?string
{
return $this->currency;
}
public function setCurrency(string $currency): self
{
$this->currency = $currency;
return $this;
}
public function getPriceUah(): ?float
{
return $this->priceUah;
}
public function setPriceUah(float $priceUah): self
{
$this->priceUah = $priceUah;
return $this;
}
public function getPriceUsd(): ?float
{
return $this->priceUsd;
}
public function setPriceUsd(float $priceUsd): self
{
$this->priceUsd = $priceUsd;
return $this;
}
public function getPriceEur(): ?float
{
return $this->priceEur;
}
public function setPriceEur(float $priceEur): self
{
$this->priceEur = $priceEur;
return $this;
}
public function getPriceMdl(): ?float
{
return $this->priceMdl;
}
public function setPriceMdl(float $priceMdl): self
{
$this->priceMdl = $priceMdl;
return $this;
}
public function getPriceUzs(): ?float
{
return $this->priceUzs;
}
public function setPriceUzs(float $priceUzs): self
{
$this->priceUzs = $priceUzs;
return $this;
}
public function getPricePln(): ?float
{
return $this->pricePln;
}
public function setPricePln(float $pricePln): self
{
$this->pricePln = $pricePln;
return $this;
}
public function getDate(): ?\DateTimeInterface
{
return $this->date;
}
public function setDate(\DateTimeInterface $date): self
{
$this->date = $date;
return $this;
}
public function getLength(): ?int
{
return $this->length;
}
public function setLength(int $length): self
{
$this->length = $length;
return $this;
}
public function getTransport(): ?string
{
return $this->transport;
}
public function setTransport(string $transport): self
{
$this->transport = $transport;
return $this;
}
public function getFood(): ?string
{
switch ($this->food){
case 'ro':
case 'ob':
case 'ao':
return 'Без питания';
case 'bb':
return 'Завтраки';
case 'hb':
return 'Полупансион (завтрак + ужин)';
case 'hb+':
return 'Полупансион +';
case 'fb':
return 'Полный пансион';
case 'fb+':
return 'Полный пансион +';
case 'ai':
return 'Всё включено';
case 'uai':
return 'Ультра всё включено';
default:
return 'Питание не определено';
}
}
public function setFood(string $food): self
{
$this->food = $food;
return $this;
}
public function getRoom(): ?string
{
return $this->room;
}
public function setRoom(string $room): self
{
$this->room = $room;
return $this;
}
public function getBest(): ?int
{
return $this->best;
}
public function setBest(int $best): self
{
$this->best = $best;
return $this;
}
public function getLast(): ?\DateTimeInterface
{
return $this->last;
}
public function setLast(\DateTimeInterface $last): self
{
$this->last = $last;
return $this;
}
public function getFromCity(): ?City
{
return $this->fromCity;
}
public function setFromCity(?City $fromCity): self
{
$this->fromCity = $fromCity;
return $this;
}
public function getExchange(): ?ExchangeRate
{
return $this->exchange;
}
public function setExchange($exchange): self
{
$this->exchange = $exchange;
return $this;
}
public function getDateString(): ?string
{
return $this->date->format('d.m.Y');
}
// public function getPriceUah()
// {
// return number_format(round($this->getPrice() * $this->exchange->getAsk(), 2), 2, ',', ' ');
// }
public function getOtpuskUrl()
{
return '<a href="https://www.otpusk.com/hotel/' . $this->id->getId() . '-' . $this->id->getHrefName() . '/' . $this->offerId . '" target="_blank">Отпуск URL</a>';
}
public function getCityWeightCurrent(): string
{
$month = $this->date->format('n');
if($weights = $this->city->getCitiesWeights()){
if(!is_null($weights->get($month - 1)) && $weights->get($month - 1)->getMonth() == $month)
return $weights->get($month - 1)->getWeight();
else{
foreach ($weights as $index => $weight) {
if($weight->getMonth() == $month)
return $weight->getWeight();
}
}
}
return '';
}
/**
*
* Get data for price-quality coefficient calculation
*
*/
public function getCityWeightCurrentCoeff()
{
$weight = $this->getCityWeightCurrent();
switch ($weight){
case 1:
return 0.7;
case 2:
return 1;
case 3:
return 1.3;
case 0:
case "":
default:
return 0.1;
}
}
public function getFoodCoeff()
{
switch ($this->getFood()){
case 'ro':
case 'ob':
case 'ao':
return 0.6;
case 'bb':
return 0.8;
case 'hb':
return 1;
//case 'hb+':return 1.35;
case 'fb':
return 1.2;
//case 'fb+': return 1.45;
case 'ai':
return 1.5;
case 'uai':
return 1.6;
}
}
public function getStarsCoeff()
{
switch ($this->id->getStars()){
case '1':
return 1;
case '2':
return 1.1;
case '3':
return 1.2;
case '4':
return 1.5;
case '4+':
return 1.75;
case '5':
return 2;
case '5+':
return 2.15;
}
}
public function getLengthCoeff()
{
return $this->getLength();
return round(1 + $this->getLength() / 150, 3);
}
public function getRatingavgCoeff()
{
if (empty($this->id->getRatingAvg()) || (int)$this->id->getRatingAvg()<=0) return 0;
return $this->id->getRatingAvg();
}
public function getTransportCoeff()
{
switch ($this->transport){
case 'air':
return 1.5;
case 'bus':
return 1.2;
default:
return 0.5;
}
}
public function getServicesLineText()
{
$services = $this->id->getServices();
if(strpos($services, 'one_line_beach'))
return '1я линия пляжа';
elseif(strpos($services, 'two_line_beach'))
return '2я линия пляжа';
else
return '3я и далее линия пляжа';
}
public function getServicesLineTextCoeff()
{
$services = $this->id->getServices();
if(strpos($services, 'one_line_beach'))
return 1.5;
elseif(strpos($services,'two_line_beach'))
return 1.2;
else
return 0.75;
}
public function getPriceCurr()
{
return $this->price . ' ' . strtoupper($this->currency);
}
public function bestFormula()
{
$food = $this->getFoodCoeff();
$stars = $this->getStarsCoeff();
$rating = $this->getRatingavgCoeff();
$weight = $this->getCityWeightCurrentCoeff();
$transport = $this->getTransportCoeff();
$line = $this->getServicesLineTextCoeff();
$uah = (double) str_replace(',', '.', str_replace(' ', '', $this->getPriceUah()));
return '( ( (1*'.$food.'/1.6*10) + (1*'.$transport.'/1.5*10) + (1.1*('.$rating.'*'.$rating.')/10) + (0.8*'.$weight.'/1.3*10) ) * '.$this->length.' * (1.2*'.$stars.'/2*10) * (0.9*'.$line.'/1.5*10) / '.$this->getPriceUah().' ) * 10 000 = '.round(( ( (1*($food/1.6)*10) + (1*($transport/1.5)*10) + (1.1*($rating*$rating/10)) + (0.8*($weight/1.3)*10) ) * $this->length * (1.2*($stars/2)*10) * (0.9*($line/1.5)*10) / $this->getPriceUah() ) * 10000);
return '(' . $food . ' * ' . $stars . ' * ' . round(1+$this->length/150, 3) . ' * ' . $weight . ' * ' . $transport . ' * ' . $line. ' * (' . ($rating) . '/4) ) / ' . $this->getPriceUah() . ' * 1 000 000 000 = ' . round(($food * $stars * (1+$this->length/150) * $weight * $transport * $line * round($rating/4,3)) / $uah * 1000000000, 0);
}
public function getStarsImg()
{
try{
return str_repeat('☆', (int)$this->id->getStars());
} catch (EntityNotFoundException $e){
return '';
}catch (RuntimeError $e){
return '';
}
}
public function getRatingAvg()
{
try{
return $this->id->getRatingAvg();
} catch (EntityNotFoundException $e){
return '';
}catch (RuntimeError $e){
return '';
}
}
public function getPriceKzt(): ?string
{
return $this->priceKzt;
}
public function setPriceKzt(string $priceKzt): self
{
$this->priceKzt = $priceKzt;
return $this;
}
public function getPriceCzk(): ?string
{
return $this->priceCzk;
}
public function setPriceCzk(string $priceCzk): self
{
$this->priceCzk = $priceCzk;
return $this;
}
public function getPriceHuf(): ?string
{
return $this->priceHuf;
}
public function setPriceHuf(string $priceHuf): self
{
$this->priceHuf = $priceHuf;
return $this;
}
}