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

class Bank_Model extends CI_Model {
  
  private $tableName = 'mstr_bank';
  
  function __construct() 
  {
    /* Call the Model constructor */
    parent::__construct();
  }

	function save_bank(&$bank_data,$bank_id=false)
	{
		if (!$bank_id)
		{
			$this->db->insert($this->tableName,$bank_data);
		}else {
			$this->db->where('id', $bank_id);
			return $this->db->update($this->tableName,$bank_data);
			
		}
		
	}	
	
	function get_all_bank() {
		$this->db->select($this->tableName.'.*');
		$this->db->order_by("bank_id", "desc");
		$this->db->where("bank_status",1);//("id !=",$id);
		$query = $this->db->get($this->tableName);
		return $query->result_array();
	}
	
	public function get_bank_info($id)
	 {
		$this->db->select('*');
		$this->db->from($this->tableName);
		$this->db->where("bank_id", $id);
		$this->db->order_by("bank_id", "desc");
		$query = $this->db->get();
		return $query->row_array(); 
	 }
	
	public function delete_bank($bank_id)
	{
		$this->db->where('bank_id', $bank_id);
		$this->db->delete($this->tableName);
	
	}

	public function disable_bank($bank_id)
	{
		$data = array(
			'status' => 0
		);	
		$this->db->where('id', $bank_id);
		$this->db->update($this->tableName, $data);
	}
	
	public function enable_bank($bank_id)
	{
		$data = array(
			'status' => 1
		);	
		$this->db->where('id', $bank_id);
		$this->db->update($this->tableName, $data);
		
	}
	/* Get all banks */
    public function get_banks()
    {
        return $this->db
            ->order_by('bank_name', 'ASC')
            ->get('banks')
            ->result();
    }

    /* Get branches by bank */
    public function get_branches_by_bank($bank_id)
    {
        return $this->db
            ->where('bank_id', $bank_id)
            ->order_by('branch_name', 'ASC')
            ->get('bank_branches')
            ->result();
    }

    /* Get single bank */
    public function get_bank($bank_id)
    {
        return $this->db
            ->where('bank_id', $bank_id)
            ->get('banks')
            ->row();
    }

    /* Get single branch */
    public function get_branch($branch_id)
    {
        return $this->db
            ->where('id', $branch_id)
            ->get('bank_branches')
            ->row();
    }
}