src/Uniski/ResourceBundle/Entity/PriceRate.php line 23

Open in your IDE?
  1. <?php
  2. namespace Uniski\ResourceBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Uniski\CommerceBundle\Exception\PriceNotFoundException;
  5. /**
  6. * @ORM\Entity
  7. * @ORM\Table(name="price_rate")
  8. * @ORM\InheritanceType("SINGLE_TABLE")
  9. * @ORM\DiscriminatorColumn(name="rate_type", type="string")
  10. * @ORM\DiscriminatorMap({
  11. *   "price_rate" = "PriceRate",
  12. *   "hotel_rate" = "HotelRate",
  13. *   "ski_rate" = "SkiRate",
  14. *   "activity_rate" = "ActivityRate",
  15. *   "renting_rate" = "RentingRate",
  16. *   "insurance_rate" = "InsuranceRate",
  17. *   "pack_rate" = "PackRate"
  18. * })
  19. */
  20. class PriceRate
  21. {
  22.   const PRICE_MAIN_KEY 'precios';
  23.   const PRICE_PERSON_KEY 'persona';
  24.   const PRICE_ADULTS_KEY 'Adultos';
  25.   const PRICE_JUNIOR_KEY 'Junior';
  26.   const PRICE_KIDS_KEY 'NiƱos';
  27.   /**
  28.    * @var integer
  29.    *
  30.    * @ORM\Id
  31.    * @ORM\Column(name="id", type="integer")
  32.    * @ORM\GeneratedValue(strategy="IDENTITY")
  33.    */
  34.   protected $id;
  35.   /**
  36.    * @var array
  37.    *
  38.    * @ORM\Column(name="prices", type="json")
  39.    */
  40.   protected $prices;
  41.   /**
  42.    * @var   string
  43.    * @ORM\Column(name="name", type="string")
  44.    */
  45.   protected $name;
  46.   /**
  47.    * Get id
  48.    *
  49.    * @return integer
  50.    */
  51.   public function getId()
  52.   {
  53.       return $this->id;
  54.   }
  55.   /**
  56.    * Set prices
  57.    *
  58.    * @param array $prices
  59.    *
  60.    * @return PriceRate
  61.    */
  62.   public function setPrices($prices)
  63.   {
  64.       $this->prices $prices;
  65.       return $this;
  66.   }
  67.   /**
  68.    * Get prices
  69.    *
  70.    * @return array
  71.    */
  72.   public function getPrices()
  73.   {
  74.       return $this->prices;
  75.   }
  76.   /**
  77.    * Gets the value of name.
  78.    *
  79.    * @return   string
  80.    */
  81.   public function getName()
  82.   {
  83.       return $this->name;
  84.   }
  85.   /**
  86.    * Sets the value of name.
  87.    *
  88.    * @param   string $name the name
  89.    *
  90.    * @return self
  91.    */
  92.   public function setName($name)
  93.   {
  94.       $this->name $name;
  95.       return $this;
  96.   }
  97.   public static function getModel($options null)
  98.   {
  99.     return [self::PRICE_MAIN_KEY => [self::PRICE_PERSON_KEY => '']];
  100.   }
  101.   public function getPersonPrice($gross true)
  102.   {
  103.     //Verify base model
  104.     if (!isset($this->prices[PriceRate::PRICE_MAIN_KEY]) ||
  105.         !isset($this->prices[PriceRate::PRICE_MAIN_KEY][PriceRate::PRICE_PERSON_KEY]) ||
  106.         !is_numeric($this->prices[PriceRate::PRICE_MAIN_KEY][PriceRate::PRICE_PERSON_KEY]))
  107.           throw new PriceNotFoundException("Invalid model");
  108.     $price floatval($this->prices[self::PRICE_MAIN_KEY][self::PRICE_PERSON_KEY]);
  109.     if ($gross) {
  110.       $price /= ($this->percentage);
  111.     }
  112.     return round($price3);
  113.   }
  114.   public function getKeyPrice($key$gross true)
  115.   {
  116.     if ($this->days == null || $this->days 1$days 1;
  117.     else $days $this->days;
  118.     if (!is_numeric($this->prices[self::PRICE_MAIN_KEY][$key])) {
  119.       throw new PriceNotFoundException("There is no price for key $key");
  120.     }
  121.     $price $this->prices[self::PRICE_MAIN_KEY][$key] / $days;
  122.     if ($gross) {
  123.       $price /= ($this->percentage);
  124.     }
  125.     return round($price3);
  126.   }
  127. }