<?php  

class cleanto_frequently_discount{
	public $id;
	public $discount_typename;
	public $days;
	public $d_type;
	public $rates;
	public $status;
	public $label;
	public $booking_count;
	public $order_id;
	public $stripe_plan_id;
	public $table_name="ct_frequently_discount";
	public $table_payment="ct_payments";
	public $conn;
	/*Function for Read All data from table*/
	public function add_discount_freq(){
		$query="insert into `".$this->table_name."` (`id`,`discount_typename`,`days`,`d_type`,`rates`,`labels`,`booking_count`,`stripe_plan_id`,`status`) values(NULL,'".$this->discount_typename."','".$this->days."','".$this->d_type."','".$this->rates."','".$this->label."','".$this->booking_count."','".$this->stripe_plan_id."','D')";
		$result=mysqli_query($this->conn,$query);			
		return $result;
	}
	/*Function for Read All data from table*/
	public function readall(){
		$query="select * from `".$this->table_name."`";
		$result=mysqli_query($this->conn,$query);			
		return $result;
	}
	/*Function for Read Only one data matched with Id */
	public function readone(){
		$query="select * from `".$this->table_name."` where `id`='".$this->id."'";
		$result=mysqli_query($this->conn,$query);
		$value=mysqli_fetch_array($result);
		return $value;
	}
	public function update_discount_status(){
		$query="update `".$this->table_name."` set `status`='".$this->status."' where `id`='".$this->id."'";
		$result=mysqli_query($this->conn,$query);
		return $result;
	}
	public function update_discount_freq_once(){
		$query="update `".$this->table_name."` set `discount_typename`='".$this->discount_typename."',`labels`='".$this->label."' where `id`='".$this->id."'";
		$result=mysqli_query($this->conn,$query);
		return $result;
	}
	public function update_discount_freq(){
		$query="update `".$this->table_name."` set `discount_typename`='".$this->discount_typename."',`d_type`='".$this->d_type."',`days`='".$this->days."',`rates`='".$this->rates."',`labels`='".$this->label."',`booking_count`='".$this->booking_count."' where `id`='".$this->id."'";
		$result=mysqli_query($this->conn,$query);
		return $result;
	}
	public function delete_discount_freq(){
		$query="delete from `".$this->table_name."` where `id`='".$this->id."'";
		$result=mysqli_query($this->conn,$query);
		return $result;
	}
	/**/
	public function readall_front(){
		$query="select * from `".$this->table_name."` where `status` = 'E' order by `id` DESC ";
		$result=mysqli_query($this->conn,$query);	
		return $result;
	}
	public function readall_first_once(){
		$query="select * from `".$this->table_name."` order by `id` limit 1";
		$result=mysqli_query($this->conn,$query);			
		return $result;
	}
	/**/
	public function readall_freq_dis_for_display_in_scrollbar(){
		$query="select * from `".$this->table_name."` where `status` = 'E' limit 1 ";
		$result=mysqli_query($this->conn,$query);	
		return $result;
	}
	public function update_discount_freq_stripe_id(){
		$query="update `".$this->table_name."` set `stripe_plan_id`='".$this->stripe_plan_id."' where `id`='".$this->id."'";
		$result=mysqli_query($this->conn,$query);
		return $result;
	}
	public function count_rec_id_in_payment(){
		$query="select count(`id`) as `p_count` from `".$this->table_payment."` where `frequently_discount` = '".$this->id."'";
		$result=mysqli_query($this->conn,$query);
		$value = mysqli_fetch_assoc($result);
		return $value["p_count"];
	}
	/*Function for get frequently discount id*/
  public function get_frequently_discount_id(){
		$query="select `frequently_discount` from `ct_payments` where `order_id`='".$this->order_id."'";
		$result=mysqli_query($this->conn,$query);  
		$value = mysqli_fetch_array($result);   
		return $value[0];
	}																				 
}
?>