<?php
class WithdrawlModel extends CI_Model {
    function __construct() {
        parent::__construct();
        $this->load->database();
    }

    public function add_withdrawl($data) {
        //$this->db->insert('lkqou_vbizz_withdrawl',$data);
        $this->db->insert('withdrawls',$data);
        return true;
    }

    function all_withdrawls_count() {
//        $query = $this->db->get('lkqou_vbizz_withdrawl');
        $query = $this->db->get('withdrawls');
        return $query->num_rows();
    }

    function all_withdrawls($limit, $start, $col, $dir) {
//        $sql = " Select a.id, b.account_name as account, a.amount, c.username as created_by, a.created from lkqou_vbizz_withdrawl as a" . " left join lkqou_vbizz_accounts as b on a.account_id=b.id" .
//        " left join lkqou_users as c on a.created_by=c.id" .
//        " Order by a.{$col} {$dir}" .
//        " Limit {$limit} Offset {$start}";
        $sql = " Select a.ID as id, b.ACCOUNT_NAME as account, a.AMOUNT as amount, c.NAME as created_by, a.CREATED as created,a.STATUS from withdrawls as a" . " left join ACCOUNTS as b on a.ACCOUNT_ID=b.ID" .
        " left join PEOPLE as c on a.CREATED_BY=c.ID";
        if($col)
            $sql.= " Order by a.{$col} {$dir}";
        if($limit && $start)
            $sql.= " Limit {$limit} Offset {$start}";
        $query = $this->db->query($sql);

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

    function withdrawls_search($limit,$start,$search,$col,$dir) {
//        $sql = " Select a.id, b.account_name as account, a.amount, c.username as created_by, a.created from lkqou_vbizz_withdrawl as a left join lkqou_vbizz_accounts as b on a.account_id=b.id left join lkqou_users as c on a.created_by=c.id where b.account_name Like '%{$search}%' or  b.account_name Like '%{$search}%'  Order by a.{$col} {$dir} Limit {$limit} Offset {$start}";
        $sql = "Select a.ID as id, b.ACCOUNT_NAME as account, a.AMOUNT as amount, c.NAME as created_by, a.CREATED as created,a.STATUS from withdrawls as a" . " left join ACCOUNTS as b on a.ACCOUNT_ID=b.ID" .
        " left join PEOPLE as c on a.CREATED_BY=c.ID where b.ACCOUNT_NAME Like '%{$search}%' or  b.ACCOUNT_NAME Like '%{$search}%'";
        if($col)
            $sql.= " Order by a.{$col} {$dir}";
        if($limit && $start)
            $sql.= " Limit {$limit} Offset {$start}";
//        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 withdrawls_search_count($search) {
//        $sql = " Select a.id, b.account_name as account, a.amount, c.username as created_by, a.created from lkqou_vbizz_withdrawl as a" .
//                " left join lkqou_vbizz_accounts as b on a.account_id=b.id" .
//                " left join lkqou_users as c on a.created_by=c.id" .
//                " where b.account_name Like '%{$search}%' or " .
//                " b.account_name Like '%{$search}%' ";
          $sql = "Select a.ID as id, b.ACCOUNT_NAME as account, a.AMOUNT as amount, c.NAME as created_by, a.CREATED as created,a.STATUS from withdrawls as a" . " left join ACCOUNTS as b on a.ACCOUNT_ID=b.ID" .
        " left join PEOPLE as c on a.CREATED_BY=c.ID where b.ACCOUNT_NAME Like '%{$search}%' or  b.ACCOUNT_NAME Like '%{$search}%'";
        $query = $this->db->query($sql);
        return $query->num_rows();
    }

}
