<?php  

class cleanto_services_methods_units_rates{
		
		public $id;
		public $units_id;
		public $units;
		public $rates;
        public $rules;
		public $table_name="ct_services_methods_units_rate";
		public $conn;
        /*  Admin panel methods   */
        /* Function to read all unites rates by unit id  */
        public function getallrates_byunitid(){
            $query="select * from `".$this->table_name."` where `units_id`=".$this->units_id;
            $result=mysqli_query($this->conn,$query);
            return $result;
        }
        /* Function for Delete unit price */
        public function delete_unitprice(){
            $query="delete from `".$this->table_name."` where `id`='".$this->id."' ";
            $result=mysqli_query($this->conn,$query);
            return $result;
        }
        /*  Function to update the rate of the qty of unit  */
        public function update_unitprice(){
            $query="update `".$this->table_name."` set `units`='".$this->units."',`rules`='".$this->rules."',`rates`='".$this->rates."' where `id`='".$this->id."' ";
            $result=mysqli_query($this->conn,$query);
            return $result;
        }
        /*  insert new price for the units per qty  */
        public function insert_unitprice(){
            echo $query="insert into `".$this->table_name."` (`id`,`units_id`,`units`,`rules`,`rates`) values(NULL,'".$this->units_id."','".$this->units."','".$this->rules."','".$this->rates."')";
            $result=mysqli_query($this->conn,$query);
            $value=mysqli_insert_id($this->conn);
            return $value;
        }
        /*  FOR ASSIGN DESIGN  */
        public function check_have_design($id)
        {
            $query="select * from `ct_service_methods_design` where `service_methods_id`='".$id."'";
            $result=mysqli_query($this->conn,$query);
            $value=mysqli_fetch_row($result);
            return $value;
        }
        /*  public function insert assign design to the methods units  */
        public function assign_design($tablename,$service_method_id,$designid)
        {
            $query="insert into `".$tablename."` (`id`,`service_methods_id`,`design`) values(NULL,'".$service_method_id."','".$designid."')";
            $result=mysqli_query($this->conn,$query);
            $value=mysqli_insert_id($this->conn);
            return $value;
        }
        /*  public function insert assign design to the methods units  */
        public function update_design($tablename,$service_method_id,$designid)
        {
            $query="update `".$tablename."` set `design`='".$designid."' where `service_methods_id`='".$service_method_id."' ";
            $result=mysqli_query($this->conn,$query);
            return $result;
        }
	public function get_rate_duration()
	{
		$query="SELECT `urduration` FROM `".$this->table_name."` WHERE `units_id`='".$this->units_id."' AND `units`='".$this->units."' AND `rules`='E'";
		$result=mysqli_query($this->conn,$query);
		return $result;
	}
	public function get_rate_duration_g()
	{
		$query="SELECT `urduration` FROM `".$this->table_name."` WHERE `units_id`='".$this->units_id."' AND `units`='".$this->units."' AND `rules`='G'";
		$result=mysqli_query($this->conn,$query);
		return $result;
	}
}
?>