<?php  

class cleanto_services_addon_rates{
		
		public $id;
		public $addon_service_id;
		public $unit;
        public $rate;
        public $rules;
		public $maxlimit;
		public $table_name="ct_addon_service_rate";
		public $conn;
		/*Function for Delete service*/
		public function delete_addon_service_rate(){
			$query="delete from `".$this->table_name."` where `id`='".$this->id."' ";
			$result=mysqli_query($this->conn,$query);
			return $result;
		}
		/*Function for Read All data from table*/
        /* used */
		public function readall(){
			$query="select * from `".$this->table_name ."` where `addon_service_id` = ".$this->addon_service_id;
			$result=mysqli_query($this->conn,$query);			
			return $result;
		}
        /* update the rate of the given qty and in adons */
        /* used  */
        public function update_addonprice(){
            $query="update `".$this->table_name."` set `unit`='".$this->unit."',`rules`='".$this->rules."',`rate`='".$this->rate."' where `id`='".$this->id."' ";
            $result=mysqli_query($this->conn,$query);
            return $result;
        }
        /* insert new price for the units per qty */
        /* used */
        public function insert_addonprice(){
            $query="insert into `".$this->table_name."` (`id`,`addon_service_id`,`unit`,`rules`,`rate`)  values(NULL,'".$this->addon_service_id."','".$this->unit."','".$this->rules."','".$this->rate."')";
            $result=mysqli_query($this->conn,$query);
            $value=mysqli_insert_id($this->conn);
            return $value;
        }
		public function readone_from_serviceid(){
		    $query="select * from `".$this->table_name."` where `addon_service_id`='".$this->addon_service_id."'";
			$result=mysqli_query($this->conn,$query);
			$value=mysqli_fetch_array($result);
			return $value;
		}
		
		public function get_rate_by_service_addon_ids(){
            $query="select * from `".$this->table_name."` where `addon_service_id`=".$this->addon_service_id." and `unit` = ".$this->maxlimit." LIMIT 1";
            $result=mysqli_query($this->conn,$query);
			$value = mysqli_fetch_array($result);
			return $value;
        }
	public function get_rate_duration()
	{
		$query="SELECT `arduration` FROM `".$this->table_name."` WHERE `addon_service_id`='".$this->addon_service_id."' AND `unit`='".$this->unit."' AND `rules`='E'";
		$result=mysqli_query($this->conn,$query);
		return $result;
	}
	public function get_rate_duration_g()
	{
		$query="SELECT `arduration` FROM `".$this->table_name."` WHERE `addon_service_id`='".$this->addon_service_id."' AND `unit`='".$this->unit."' AND `rules`='G'";
		$result=mysqli_query($this->conn,$query);
		return $result;
	}
}
?>