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

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

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

	   $sql = " Select a.id, b.account_name as from_account, c.account_name as to_account, a.amount, d.username as created_by, a.created from lkqou_vbizz_banking as a".
                  " left join lkqou_vbizz_accounts as b on a.from_account=b.id".
                  " left join lkqou_vbizz_accounts as c on a.to_account=c.id".
				  " left join lkqou_users as d on a.created_by=d.id".
				  " Order by a.{$col} {$dir}".
				  " Limit {$limit} Offset {$start}";	
       $query = $this
                ->db
                ->query($sql);
        
        if($query->num_rows()>0)
        {
            return $query->result(); 
        }
        else
        {
            return null;
        }
        
    }
   
    function bankings_search($limit,$start,$search,$col,$dir)
    {

		$sql = " Select a.id, b.account_name as from_account, c.account_name as to_account, a.amount, d.username as created_by, a.created from lkqou_vbizz_banking as a".
                  " left join lkqou_vbizz_accounts as b on a.from_account=b.id".
                  " left join lkqou_vbizz_accounts as c on a.to_account=c.id".
				  " left join lkqou_users as d on a.created_by=d.id".
				  " where b.account_name Like '%{$search}%' or ".
				  " b.account_name Like '%{$search}%' ".
				  " Order by a.{$col} {$dir}".
				  " Limit {$limit} Offset {$start}";	
        $query = $this
                ->db
                ->query($sql);

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

    function bankings_search_count($search)
    {
		$sql = " Select a.id, b.account_name as from_account, c.account_name as to_account, a.amount, d.username as created_by, a.created from lkqou_vbizz_banking as a".
                  " left join lkqou_vbizz_accounts as b on a.from_account=b.id".
                  " left join lkqou_vbizz_accounts as c on a.to_account=c.id".
				  " left join lkqou_users as d on a.created_by=d.id".
				  " where b.account_name Like '%{$search}%' or ".
				  " b.account_name Like '%{$search}%' ";	
        $query = $this
                ->db
                ->query($sql);
    
        return $query->num_rows();
    } 
	
	
	
	
}