<?phpnamespace CoreBundle\Entity\Vehicles;use DateTime;use Application\Sonata\MediaBundle\Entity\Media;use CoreBundle\Entity\ConfiguratorOffer;use CoreBundle\Entity\User;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;/** * VehicleItem */classVehicleItem{    /**     * @var integer     */    private $id;    /**     * @var float     */    private $price;    /**     * @var integer     */    private $alt_price;    /**     * @var float     */    private $alt_rate;    /**     * @var integer     */    private $preorder_price;    /**     * @var integer     */    private $rent_price;    /**     * @var integer     */    private $year;    /**     * @var integer     */    private $mileage = 0;    /**     * @var integer     */    private $state = 0;    /**     * @var User     */    private $creator;    /**     * @var Equipment     */    private $equipment;    /**     * @var Variation     */    private $variation;    /**     * @var Vehicle     */    private $vehicle;    /**     * @var integer     */    private $single_owner = 0;    /**     * @var integer     */    private $service_book = 0;    /**     * @var integer     */    private $buy_in_ukraine = 0;    /**     * @var integer     */    private $no_accident = 0;    /**     * @var integer     */    private $credit_min_amount = 0;    /**     * @var integer     */    private $credit_percent = 0;    /**     * @var integer     */    private $has_nds = 0;    /**     * @var integer     */    private $sold = 0;    /**     * @var integer     */    private $deposit = 0;    /**     * @var boolean     */    private $specify_price = 0;    /**     * @var Collection     */    private $offer;    /**     * @var string     */    private $programm;    /**     * @var Specification     */    private $specification;    /**     * @var integer     */    private $alt_usd_price;    /**     * @var string     */    private $approved_warranty;    /**     * @var string     */    private $factory_warranty;    /**     * @var string     */    private $modification;    /**     * @var string     */    private $exterior;    /**     * @var string     */    private $interior_ua;    /**     * @var string     */    private $interior_ru;    /**     * @var Media     */    private $file;    /**     * @var string     */    private $approved_warranty_ua;    /**     * @var string     */    private $approved_warranty_ru;    /**     * @var string     */    private $factory_warranty_ua;    /**     * @var string     */    private $factory_warranty_ru;    /**     * @var integer     */    private $is_reserved = 0;    /**     * @var integer     */    private $economic_engine = 0;    /**     * @var integer     */    private $excellent_technical_condition = 0;    /**     * @var integer     */    private $official_service = 0;    /**     * @var integer     */    private $additional_rubber = 0;    /**     * @var integer     */    private $under_warranty = 0;    /**     * @var integer     */    private $top_equipment = 0;    /**     * @var integer     */    private $additional_equipment = 0;    /**     * @var integer     */    private $official_car = 0;    /**     * @var integer     */    private $price_with_PDV = 0;    /**     * @var integer     */    private $best_price = 0;    /**     * @var integer     */    private $low_mileage = 0;    /**     * @var integer     */    private $increased_security = 0;    /**     * @var integer     */    private $native_color = 0;    /**     * Get id     *     * @return integer     */    public function getId()    {        return $this->id;    }    /**     * Set price     *     * @param float $price     *     * @return VehicleItem     */    public function setPrice($price)    {        $this->price = $price;        return $this;    }    /**     * Get price     *     * @return float     */    public function getPrice()    {        return $this->price;    }    /**     * Set altPrice     *     * @param integer $altPrice     *     * @return VehicleItem     */    public function setAltPrice($altPrice)    {        $this->alt_price = $altPrice;        return $this;    }    /**     * Get altPrice     *     * @return integer     */    public function getAltPrice()    {        return (int)$this->alt_price;    }    /**     * Set altRate     *     * @param float $altRate     *     * @return VehicleItem     */    public function setAltRate($altRate)    {        $this->alt_rate = $altRate;        return $this;    }    /**     * Get altRate     *     * @return float     */    public function getAltRate()    {        return $this->alt_rate;    }    /**     * Set preorderPrice     *     * @param integer $preorderPrice     *     * @return VehicleItem     */    public function setPreorderPrice($preorderPrice)    {        $this->preorder_price = $preorderPrice;        return $this;    }    /**     * Get preorderPrice     *     * @return integer     */    public function getPreorderPrice()    {        return $this->preorder_price;    }    /**     * Set year     *     * @param integer $year     *     * @return VehicleItem     */    public function setYear($year)    {        $this->year = $year;        return $this;    }    /**     * Get year     *     * @return integer     */    public function getYear()    {        return $this->year;    }    /**     * Set mileage     *     * @param integer $mileage     *     * @return VehicleItem     */    public function setMileage($mileage)    {        $this->mileage = $mileage;        return $this;    }    /**     * Get mileage     *     * @return integer     */    public function getMileage()    {        return $this->mileage;    }    /**     * Set state     *     * @param integer $state     *     * @return VehicleItem     */    public function setState($state)    {        $this->state = $state;        return $this;    }    /**     * @return bool     */    public function getState()    {        return $this->state > 0;    }    /**     * @return bool     */    public function isActive()    {        return $this->state > 0;    }    /**     * Set creator     *     * @param User $creator     *     * @return VehicleItem     */    public function setCreator(User $creator = null)    {        $this->creator = $creator;        return $this;    }    /**     * Get creator     *     * @return User     */    public function getCreator()    {        return $this->creator;    }    /**     * Set equipment     *     * @param Equipment|null $equipment     *     * @return VehicleItem     */    public function setEquipment(Equipment $equipment = null)    {        $this->equipment = $equipment;        return $this;    }    /**     * Get equipment     *     * @return Equipment     */    public function getEquipment()    {        return $this->equipment;    }    /**     * Set variation     *     * @param Variation|null $variation     *     * @return VehicleItem     */    public function setVariation(Variation $variation = null)    {        $this->variation = $variation;        return $this;    }    /**     * Get variation     *     * @return Variation     */    public function getVariation()    {        return $this->variation;    }    /**     * Set specification     *     * @param Specification|null $specification     *     * @return VehicleItem     */    public function setSpecification(Specification $specification = null)    {        $this->specification = $specification;        return $this;    }    /**     * Get specification     *     * @return Specification     */    public function getSpecification()    {        return $this->specification;    }    public function __toString()    {        //TODO refactor Negated boolean expression is always false.        if (!$this->getEquipment() || !$this->getVariation()) {            return '';        }        return $this->getEquipment() . ' [' . $this->getVariation()->getTitle() . ']';    }    /**     * @return false|float|int     */    public function calcPrice()    {        if ($this->getAltPrice()) {            return $this->getAltPrice();        }        if ($this->getAltRate()) {            $rate = $this->getAltRate();        } else {            if($this->getVariation()->getVehicle()) {                $rate = $this->getVariation()->getVehicle()->getDealer()->getRate();            } else {                $rate = 0;            }        }        if ($this->getAltUsdPrice()) {            return ceil($this->getAltUsdPrice() * $rate);        }        return ceil($this->getPrice() * $rate);    }    public function fullPrice(): float    {        return ceil($this->getPrice() * $this->getVariation()->getVehicle()->getDealer()->getRate());    }    /**     * Set vehicle     *     * @param Vehicle|null $vehicle     *     * @return VehicleItem     */    public function setVehicle(Vehicle $vehicle = null)    {        $this->vehicle = $vehicle;        return $this;    }    /**     * Get vehicle     *     * @return Vehicle     */    public function getVehicle()    {        return $this->vehicle;    }    /**     * Set hasNds     *     * @param integer $hasNds     *     * @return VehicleItem     */    public function setHasNds($hasNds)    {        $this->has_nds = $hasNds;        return $this;    }    /**     * @return bool     */    public function getHasNds()    {        return $this->has_nds > 0;    }    /**     * Set sold     *     * @param integer $sold     *     * @return VehicleItem     */    public function setSold($sold)    {        $this->sold = $sold;        if ($this->date_of_sale === null && $sold) {            $this->date_of_sale = new DateTime('now');        } else {            $this->date_of_sale = null;        }        return $this;    }    /**     * @return bool     */    public function getSold()    {        return $this->sold > 0;    }    /**     * Set deposit     *     * @param integer $deposit     *     * @return VehicleItem     */    public function setDeposit($deposit)    {        $this->deposit = $deposit;        return $this;    }    /**     * @return bool     */    public function getDeposit()    {        return $this->deposit > 0;    }    /**     * Set rentPrice     *     * @param integer $rentPrice     *     * @return VehicleItem     */    public function setRentPrice($rentPrice)    {        $this->rent_price = $rentPrice;        return $this;    }    /**     * Get rentPrice     *     * @return integer     */    public function getRentPrice()    {        return $this->rent_price;    }    /**     * Set singleOwner     *     * @param integer $singleOwner     *     * @return VehicleItem     */    public function setSingleOwner($singleOwner)    {        $this->single_owner = $singleOwner;        return $this;    }    /**     * @return bool     */    public function getSingleOwner()    {        return $this->single_owner > 0;    }    /**     * Set serviceBook     *     * @param integer $serviceBook     *     * @return VehicleItem     */    public function setServiceBook($serviceBook)    {        $this->service_book = $serviceBook;        return $this;    }    /**     * @return bool     */    public function getServiceBook()    {        return $this->service_book > 0;    }    /**     * Set buyInUkraine     *     * @param integer $buyInUkraine     *     * @return VehicleItem     */    public function setBuyInUkraine($buyInUkraine)    {        $this->buy_in_ukraine = $buyInUkraine;        return $this;    }    /**     * @return bool     */    public function getBuyInUkraine()    {        return $this->buy_in_ukraine > 0;    }    /**     * Set noAccident     *     * @param integer $noAccident     *     * @return VehicleItem     */    public function setNoAccident($noAccident)    {        $this->no_accident = $noAccident;        return $this;    }    /**     * @return bool     */    public function getNoAccident()    {        return $this->no_accident > 0;    }    /**     * Set altUsdPrice     *     * @param integer $altUsdPrice     *     * @return VehicleItem     */    public function setAltUsdPrice($altUsdPrice)    {        $this->alt_usd_price = $altUsdPrice;        return $this;    }    /**     * Get altUsdPrice     *     * @return integer     */    public function getAltUsdPrice()    {        return $this->alt_usd_price;    }    /**     * Set modification     *     * @param string $modification     *     * @return VehicleItem     */    public function setModification($modification)    {        $this->modification = $modification;        return $this;    }    /**     * Get modification     *     * @return string     */    public function getModification()    {        return $this->modification;    }    /**     * Set exterior     *     * @param string $exterior     *     * @return VehicleItem     */    public function setExterior($exterior)    {        $this->exterior = $exterior;        return $this;    }    /**     * Get exterior     *     * @return string     */    public function getExterior()    {        return $this->exterior;    }    /**     * Set interiorUa     *     * @param string $interiorUa     *     * @return VehicleItem     */    public function setInteriorUa($interiorUa)    {        $this->interior_ua = $interiorUa;        return $this;    }    /**     * Get interiorUa     *     * @return string     */    public function getInteriorUa()    {        return $this->interior_ua;    }    /**     * Set interiorRu     *     * @param string $interiorRu     *     * @return VehicleItem     */    public function setInteriorRu($interiorRu)    {        $this->interior_ru = $interiorRu;        return $this;    }    /**     * Get interiorRu     *     * @return string     */    public function getInteriorRu()    {        return $this->interior_ru;    }    /**     * Set file     *     * @param Media $file     *     * @return VehicleItem     */    public function setFile(Media $file = null)    {        $this->file = $file;        return $this;    }    /**     * Get file     *     * @return Media     */    public function getFile()    {        return $this->file;    }    /**     * Set approvedWarrantyUa     *     * @param string $approvedWarrantyUa     *     * @return VehicleItem     */    public function setApprovedWarrantyUa($approvedWarrantyUa)    {        $this->approved_warranty_ua = $approvedWarrantyUa;        return $this;    }    /**     * Get approvedWarrantyUa     *     * @return string     */    public function getApprovedWarrantyUa()    {        return $this->approved_warranty_ua;    }    /**     * Set approvedWarrantyRu     *     * @param string $approvedWarrantyRu     *     * @return VehicleItem     */    public function setApprovedWarrantyRu($approvedWarrantyRu)    {        $this->approved_warranty_ru = $approvedWarrantyRu;        return $this;    }    /**     * Get approvedWarrantyRu     *     * @return string     */    public function getApprovedWarrantyRu()    {        return $this->approved_warranty_ru;    }    /**     * Set factoryWarrantyUa     *     * @param string $factoryWarrantyUa     *     * @return VehicleItem     */    public function setFactoryWarrantyUa($factoryWarrantyUa)    {        $this->factory_warranty_ua = $factoryWarrantyUa;        return $this;    }    /**     * Get factoryWarrantyUa     *     * @return string     */    public function getFactoryWarrantyUa()    {        return $this->factory_warranty_ua;    }    /**     * Set factoryWarrantyRu     *     * @param string $factoryWarrantyRu     *     * @return VehicleItem     */    public function setFactoryWarrantyRu($factoryWarrantyRu)    {        $this->factory_warranty_ru = $factoryWarrantyRu;        return $this;    }    /**     * Get factoryWarrantyRu     *     * @return string     */    public function getFactoryWarrantyRu()    {        return $this->factory_warranty_ru;    }    public function getFactoryWarranty($locale = 'ua')    {        return $locale === 'ua' ? $this->getFactoryWarrantyUa() : $this->getFactoryWarrantyRu();    }    public function getApprovedWarranty($locale = 'ua')    {        return $locale === 'ua' ? $this->getApprovedWarrantyUa() : $this->getApprovedWarrantyRu();    }    public function getInterior($locale = 'ua')    {        return $locale === 'ua' ? $this->getInteriorUa() : $this->getInteriorRu();    }    /**     * Set isReserved     *     * @param integer $isReserved     *     * @return VehicleItem     */    public function setIsReserved($isReserved)    {        $this->is_reserved = $isReserved;        return $this;    }    /**     * Get isReserved     *     * @return integer     */    public function getIsReserved()    {        return $this->is_reserved > 0;    }    /**     * Get credit_min_amount     *     * @return integer     */    public function getCreditMinAmount()    {        return $this->credit_min_amount;    }    /**     * Set credit_min_amount     *     * @return VehicleItem     */    public function setCreditMinAmount($creditMinAmount)    {        $this->credit_min_amount = $creditMinAmount;        return $this;    }    /**     * Get credit_percent     *     * @return integer     */    public function getCreditPercent()    {        return $this->credit_percent;    }    /**     * Set credit_percent     *     * @return VehicleItem     */    public function setCreditPercent($creditPercent)    {        $this->credit_percent = $creditPercent;        return $this;    }    /**     * Set economicEngine     *     * @param integer $economicEngine     *     * @return VehicleItem     */    public function setEconomicEngine($economicEngine)    {        $this->economic_engine = $economicEngine;        return $this;    }    /**     * @return bool     */    public function getEconomicEngine()    {        return $this->economic_engine > 0;    }    /**     * Set excellentTechnicalCondition     *     * @param integer $excellentTechnicalCondition     *     * @return VehicleItem     */    public function setExcellentTechnicalCondition($excellentTechnicalCondition)    {        $this->excellent_technical_condition = $excellentTechnicalCondition;        return $this;    }    /**     * @return bool     */    public function getExcellentTechnicalCondition()    {        return $this->excellent_technical_condition > 0;    }    /**     * Set officialService     *     * @param integer $officialService     *     * @return VehicleItem     */    public function setOfficialService($officialService)    {        $this->official_service = $officialService;        return $this;    }    /**     * @return bool     */    public function getOfficialService()    {        return $this->official_service > 0;    }    /**     * Set additionalRubber     *     * @param integer $additionalRubber     *     * @return VehicleItem     */    public function setAdditionalRubber($additionalRubber)    {        $this->additional_rubber = $additionalRubber;        return $this;    }    /**     * @return bool     */    public function getAdditionalRubber()    {        return $this->additional_rubber > 0;    }    /**     * Set underWarranty     *     * @param integer $underWarranty     *     * @return VehicleItem     */    public function setUnderWarranty($underWarranty)    {        $this->under_warranty = $underWarranty;        return $this;    }    /**     * @return bool     */    public function getUnderWarranty()    {        return $this->under_warranty > 0;    }    /**     * Set topEquipment     *     * @param integer $topEquipment     *     * @return VehicleItem     */    public function setTopEquipment($topEquipment)    {        $this->top_equipment = $topEquipment;        return $this;    }    /**     * Get topEquipment     *     * @return integer     */    public function getTopEquipment()    {        return $this->top_equipment > 0;    }    /**     * Set additionalEquipment     *     * @param integer $additionalEquipment     *     * @return VehicleItem     */    public function setAdditionalEquipment($additionalEquipment)    {        $this->additional_equipment = $additionalEquipment;        return $this;    }    /**     * Get additionalEquipment     *     * @return integer     */    public function getAdditionalEquipment()    {        return $this->additional_equipment > 0;    }    /**     * Set officialCar     *     * @param integer $officialCar     *     * @return VehicleItem     */    public function setOfficialCar($officialCar)    {        $this->official_car = $officialCar;        return $this;    }    /**     * @return bool     */    public function getOfficialCar()    {        return $this->official_car > 0;    }    /**     * Set priceWithPDV     *     * @param integer $priceWithPDV     *     * @return VehicleItem     */    public function setPriceWithPDV($priceWithPDV)    {        $this->price_with_PDV = $priceWithPDV;        return $this;    }    /**     * @return bool     */    public function getPriceWithPDV()    {        return $this->price_with_PDV > 0;    }    /**     * Set bestPrice     *     * @param integer $bestPrice     *     * @return VehicleItem     */    public function setBestPrice($bestPrice)    {        $this->best_price = $bestPrice;        return $this;    }    /**     * @return bool     */    public function getBestPrice()    {        return $this->best_price > 0;    }    /**     * Set lowMileage     *     * @param integer $lowMileage     *     * @return VehicleItem     */    public function setLowMileage($lowMileage)    {        $this->low_mileage = $lowMileage;        return $this;    }    /**     * @return bool     */    public function getLowMileage()    {        return $this->low_mileage > 0;    }    /**     * Set increasedSecurity     *     * @param integer $increasedSecurity     *     * @return VehicleItem     */    public function setIncreasedSecurity($increasedSecurity)    {        $this->increased_security = $increasedSecurity;        return $this;    }    /**     * @return bool     */    public function getIncreasedSecurity()    {        return $this->increased_security > 0;    }    /**     * Set nativeColor     *     * @param integer $nativeColor     *     * @return VehicleItem     */    public function setNativeColor($nativeColor)    {        $this->native_color = $nativeColor;        return $this;    }    /**     * @return bool     */    public function getNativeColor()    {        return $this->native_color > 0;    }    /**     * Set programm     *     * @param string $programm     *     * @return VehicleItem     */    public function setProgramm($programm)    {        $this->programm = $programm;        return $this;    }    /**     * Get programm     *     * @return string     */    public function getProgramm()    {        return $this->programm;    }    /**     * Set specifyPrice     *     * @param boolean $specifyPrice     *     * @return VehicleItem     */    public function setSpecifyPrice($specifyPrice)    {        $this->specify_price = $specifyPrice;        return $this;    }    /**     * Get specifyPrice     *     * @return boolean     */    public function getSpecifyPrice()    {        return $this->specify_price > 0;    }    /**     * Constructor     */    public function __construct()    {        $this->offer = new ArrayCollection();    }    /**     * Add offer     *     * @param ConfiguratorOffer $offer     *     * @return VehicleItem     */    public function addOffer(ConfiguratorOffer $offer)    {        $this->offer[] = $offer;        return $this;    }    /**     * Remove offer     *     * @param ConfiguratorOffer $offer     */    public function removeOffer(ConfiguratorOffer $offer)    {        $this->offer->removeElement($offer);    }    /**     * Get offer     *     * @return Collection     */    public function getOffer()    {        return $this->offer;    }    /**     * @var Collection     */    private $vehicleInStock;    /**     * Add vehicleInStock     *     * @param InStock $vehicleInStock     *     * @return VehicleItem     */    public function addVehicleInStock(InStock $vehicleInStock)    {        $this->vehicleInStock[] = $vehicleInStock;        return $this;    }    /**     * Remove vehicleInStock     *     * @param InStock $vehicleInStock     */    public function removeVehicleInStock(InStock $vehicleInStock)    {        $this->vehicleInStock->removeElement($vehicleInStock);    }    /**     * Get vehicleInStock     *     * @return Collection     */    public function getVehicleInStock()    {        return $this->vehicleInStock;    }    /**     * @var integer     */    private $views;    /**     * Set views     *     * @param integer $views     *     * @return VehicleItem     */    public function setViews($views)    {        $this->views = $views;        return $this;    }    /**     * Get views     *     * @return integer     */    public function getViews()    {        return $this->views;    }    /**     * @var DateTime|null     */    private $date_of_sale;    /**     * Set dateOfSale.     *     * @param DateTime|null $dateOfSale     *     * @return VehicleItem     */    public function setDateOfSale($dateOfSale = null)    {        $this->date_of_sale = $dateOfSale;        return $this;    }    /**     * Get dateOfSale.     *     * @return DateTime|null     */    public function getDateOfSale()    {        return $this->date_of_sale;    }}