<?php
class PayheadModel extends CI_Model
{
	function __construct() {
		parent::__construct();
		$this->load->database();
	}
       
	public function add_payhead($data)
	{
		$this->db->insert('lkqou_vbizz_payheads',$data);
		return true;
	}

	public function update_payhead($id, $ownerid, $data)
	{
		$this->db->where(array('id'=>$id, 'ownerid'=>$ownerid));
		$this->db->update('lkqou_vbizz_payheads', $data);
		return true;
	}
	public function get_payhead($id)
	{
		$this->db->where('id', $id);
		$query = $this->db->get('lkqou_vbizz_payheads');
		return $query->result();
	}

	public function delete_payheads($ids){
		$this->db->where_in('id', $ids);
		$this->db->delete('lkqou_vbizz_payheads');
		return true;
	}

	

	function all_payheads_count()
    {   
        $query = $this
                ->db
                ->get('lkqou_vbizz_payheads');
    
        return $query->num_rows();  

    }
    
    function all_payheads($limit,$start,$col,$dir)
    {   

		$this->db->select('*');
		$this->db->from('lkqou_vbizz_payheads');
		$this->db->order_by($col,$dir);
		$this->db->limit($limit, $start);

		$query = $this->db->get();
        
        if($query->num_rows()>0)
        {
            return $query->result(); 
        }
        else
        {
            return null;
        }
        
    }
   
    function payheads_search($limit,$start,$search_array,$col,$dir, $ownerid)
    {
        // $where = ' Where ownerid='.$ownerid;
        $where = '';

        if(isset($search_array['search'])){
            $where .= ' Where LOWER(name) like "%'.$search_array['search'].'%"';
        }
        
		$sql ='SELECT * FROM lkqou_vbizz_payheads'.
              $where.' Order by '.$col.' '.$dir.
			  ' Limit '.$limit.' Offset '.$start;
        
        $query = $this
                ->db
                ->query($sql);
    
        
        if($query->num_rows()>0)
        {
            return $query->result(); 
        }
        else
        {
            return null;
        }
    }

    function payheads_search_count($search, $ownerid)
    {
		// $where = ' Where ownerid='.$ownerid;
        $where = '';

        if(isset($search_array['search'])){
            $where .= ' where LOWER(name) like "%'.$search_array['search'].'%"';
        }
        
		$sql ='SELECT * FROM lkqou_vbizz_payheads'.
              $where;
        
        $query = $this
                ->db
                ->query($sql);
    
        return $query->num_rows();
    } 

	function dropdown_payheads()
	{
		$this->db->select('*');
		$this->db->from('lkqou_vbizz_payheads');

		$query = $this->db->get();
        
        if($query->num_rows()>0)
        {
            return $query->result(); 
        }
        else
        {
            return null;
        }

	}

	
    function get_payheads()
	{
		//get listing of all user of an owner
		
		$sql = 'SELECT * from lkqou_vbizz_payheads';
		$query = $this->db->query($sql);
		
		if($query->num_rows()>0)
        {
            return $query->result(); 
        }
        else
        {
            return null;
        }
	}

	
}