<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Adminmodel extends CI_Model {
	
	public function check_admin($username,$password)
	{
		$this->db->select('id,status');
		$this->db->from('tbl_admin');
		$this->db->where('username',$username);
		$this->db->where('password',$password);
		$query=$this->db->get();
		if($query->num_rows()>0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	public function fetch_tax()
	{
		$this->db->select('*');
		$this->db->from('tbl_tax');
	//	$this->db->join('tbl_state','tbl_state.state_id=tbl_tax.state');
		$query=$this->db->get();
		return $query->result();
	}
	public function getcountry()
	{
		$this->db->select('*');
		$query=$this->db->get('tbl_country');
		return $query->result();
	}
	public function fetchState($country_id)
	{
		$this->db->where('country_id',$country_id);
		$this->db->order_by('state_name','ASC');
		$query=$this->db->get('tbl_state');
		$output='<option value="">Select State</option>';
		foreach($query->result() as  $row)
		{
			$output .= '<option value="'.$row->state_id.'">'.$row->state_name.'</option>';
		}
		return $output;
	}
	public function taxAdd($data)
	{
		$this->db->insert('tbl_tax',$data);
	}
	public function inactive($id)
	{
		$this->db->where('id',$id);
		$this->db->set('status','N');
		$this->db->update('tbl_tax');
	}
	public function active($id)
	{
		$this->db->where('id',$id);
		$this->db->set('status','Y');
		$this->db->update('tbl_tax');
	}
	public function fetchService()
	{
		//$active='Y';
		$this->db->select('*');
		//$this->db->where('status',$active);
		$query=$this->db->get('tbl_service');
		return $query->result();
	}
	public function serviceAdd($data)
	{
		$this->db->insert('tbl_service',$data);
	}
	public function activeService()
	{
		$active='Y';
		$this->db->select('*');
		$this->db->where('status',$active);
		$query=$this->db->get('tbl_service');
		return $query->result();
	}
	public function singleService($id)
	{
		$this->db->select('*');
		$this->db->where('id',$id);
		$query=$this->db->get('tbl_service');
		return $query->result();
	}
	public function EditService($id,$data)
	{
		$this->db->where('id',$id);
		$this->db->update('tbl_service',$data);
	}
	public function user_fetch()
	{
		$this->db->select('*');
		$this->db->order_by('id','DESC');
		$query=$this->db->get('tbl_usr');
		return $query->result();
	}
	public function fetchProfile($id)
	{
		$this->db->select('*');
		$this->db->from('tbl_usr');
		$this->db->join('tbl_country','tbl_country.country_id=tbl_usr.country');
		$this->db->join('tbl_state','tbl_state.state_id=tbl_usr.state');
		$this->db->where('tbl_usr.id',$id);
		$query=$this->db->get();
		return $query->result();
	}
	public function serviceName($id)
	{
		$this->db->select('*');
		$this->db->where('id',$id);
		$query=$this->db->get('tbl_service');
		return $query->result();
	}
	public function planListing($id)
	{
		$active='Y';
		$this->db->select('*');
		$this->db->where('service_id',$id);
		$this->db->where('status',$active);
		$query=$this->db->get('tbl_service_plans');
		return $query->result();
	}
	public function inactivePalns($id)
	{
		$inactive='N';
		$this->db->select('*');
		$this->db->where('service_id',$id);
		$this->db->where('status',$inactive);
		$query=$this->db->get('tbl_service_plans');
		return $query->result();
	}
	public function fetchSingleData($id)
	{
		$this->db->select('*');
		$this->db->where('id',$id);
		$query=$this->db->get('tbl_service_plans');
		return $query->result();
	}
	public function updatePlan($data,$pid)
	{
		$this->db->where('id',$pid);
		$this->db->update('tbl_service_plans',$data);
	}
	public function addPlanDetails($data)
	{
		$this->db->insert('tbl_service_plans',$data);
	}
	public function fechOrder()
	{
		$this->db->select('*');
		$this->db->from('tbl_order');
		$this->db->order_by('tbl_order.order_id','desc');
		$this->db->join('tbl_usr','tbl_usr.id=tbl_order.user_id');
		$query=$this->db->get();
		return $query->result();
	}
	public function Orderdetails($id)
	{
		$this->db->select('*');
		$this->db->from('tbl_orderdetails');
		$this->db->join('tbl_order','tbl_order.order_id=tbl_orderdetails.order_id');
		$this->db->join('tbl_service_plans','tbl_service_plans.id=tbl_orderdetails.product_id');
		$this->db->where('tbl_orderdetails.order_id',$id);
		$query=$this->db->get();
		return $query->result();
	}
}
