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

class BrRefundModel extends CI_Model {

    function __construct()
    {
        parent::__construct();
        date_default_timezone_set('Asia/Hong_Kong');
    }
    //added refund function
    function refund_exists($invoiceid){
        // $this->db->from('adminUsers');
        // $this->db->where('LOWER(name)', $name);
        $this->db->where('invoice_id', $invoiceid);
        $this->db->where('delete_time', NULL);   
        $query = $this->db->get('brpurchase_refund');
        if($query->num_rows() >= 1){
            return false;
        } else {
            return true;
        }
    }
    function insertRefund($inputdata){
        // 'inputadminname'=>$inputadminname,
        //         'inputloginname'=>$inputloginname,
        //         'inputPassword'=>$inputPassword,
        date_default_timezone_set('Asia/Hong_Kong');
        $data = array(
            'invoice_id' => $inputdata['invoice_id'] ,
            'refund_date' => strtotime($inputdata['refund_date']) ,
            'refund_amount' => $inputdata['refund_amount'] ,

         );
        
        
         $this->db->set('update_time', time(), FALSE);
         $this->db->set('create_time', time(), FALSE);
         // $this->db->set('update_time', 'NOW()', FALSE);
         // $this->db->set('create_time', 'NOW()', FALSE);
         $query=$this->db->insert('brpurchase_refund', $data);
         return $query;
    }
    function updateRefund($inputdata){
        // 'inputadminname'=>$inputadminname,
        //         'inputloginname'=>$inputloginname,
        //         'inputPassword'=>$inputPassword,
        date_default_timezone_set('Asia/Hong_Kong');


        $data = array(
            'refund_date' => strtotime($inputdata['refund_date']) ,
            'refund_amount' => $inputdata['refund_amount'] ,
            // 'capacity' => $inputdata['capacity'] ,
            // 'description' => $dataori['description'] ,
            // // 'fullName' => $dataori['inputadminname'] ,
            // 'remark' => $dataori['remark'] ,
            


         );
        
        
         $this->db->set('update_time', time(), FALSE);
         // $this->db->set('create_time', time(), FALSE);
         // $this->db->set('update_time', 'NOW()', FALSE);
         // $this->db->set('create_time', 'NOW()', FALSE);
         $this->db->where('invoice_id', $inputdata['invoice_id']);
         $query=$this->db->update('brpurchase_refund', $data);
         return $query;
    }
    //end added refund function



    function getAllRoom($id) {
        $this->db->from('brroom');
        $this->db->where('shop_id',$id);
        $this->db->where('delete_time', NULL);
        $query = $this->db->get();
        return $query->result();
    }
     
    function insertAdmin($data){
        // 'inputadminname'=>$inputadminname,
        //         'inputloginname'=>$inputloginname,
        //         'inputPassword'=>$inputPassword,
        $data = array(
            'shop_id' => $data['shop_id'] ,
            'name' => $data['name'] ,
            'capacity' => $data['capacity'] ,
            'description' => $data['description'] ,
            // 'fullName' => $data['inputadminname'] ,
            'remark' => $data['remark'] ,
            


         );
        date_default_timezone_set('UTC');
        
         $this->db->set('update_time', time(), FALSE);
         $this->db->set('create_time', time(), FALSE);
         // $this->db->set('update_time', 'NOW()', FALSE);
         // $this->db->set('create_time', 'NOW()', FALSE);
         $query=$this->db->insert('brroom', $data);
         return $query;
    }
    function getRoom($id){
        $this->db->from('brroom');
        $this->db->where('delete_time', NULL);    
        $this->db->where('id', $id);    
        // $this->db->order_by('code');
        $query = $this->db->get();
        $ret = $query->row();
        return $ret;
    }

     function room_existsbyid($id,$shop_id,$name){
        // $this->db->from('adminUsers');
        $this->db->where('LOWER(name)', $name);
        $this->db->where('shop_id', $shop_id);
        $this->db->where('id !=', $id); 
        $this->db->where('delete_time', NULL);   
        $query = $this->db->get('brroom');
        if($query->num_rows() == 1){
            return false;
        } else {
            return true;
        }
    }

     function updateAdmin($dataori){
        // 'inputadminname'=>$inputadminname,
        //         'inputloginname'=>$inputloginname,
        //         'inputPassword'=>$inputPassword,
        $data = array(
            'shop_id' => $dataori['shop_id'] ,
            'name' => $dataori['name'] ,
            'capacity' => $dataori['capacity'] ,
            'description' => $dataori['description'] ,
            // 'fullName' => $dataori['inputadminname'] ,
            'remark' => $dataori['remark'] ,
            


         );
        date_default_timezone_set('UTC');
        
         $this->db->set('update_time', time(), FALSE);
         // $this->db->set('create_time', time(), FALSE);
         // $this->db->set('update_time', 'NOW()', FALSE);
         // $this->db->set('create_time', 'NOW()', FALSE);
         $this->db->where('id', $dataori['id']);
         $query=$this->db->update('brroom', $data);
         return $query;
    }
    function updateStatus($data){
            $data2 = array(
            'status' => $data['status'] ,
         );
        date_default_timezone_set('UTC');
        
        $this->db->set('update_time', time(), FALSE);

        $this->db->where('id', $data['id']);
        $query=$this->db->update('brroom', $data2);
        return $query;
    }
    function  deleteRoom($id){
        date_default_timezone_set('UTC');
        
        $this->db->set('delete_time', time(), FALSE);
         $this->db->where('id', $id);
        $query=$this->db->update('brroom');
        return $query;
    }
    function getRoomName($id) {
        $this->db->from('brroom');
        // $this->db->where('shop_id', 1);
         $this->db->where('id', $id);    
 
        $name=$this->db->get()->row()->name;
        return $name;
    }   
    
   
    

    
   
   
    
    
    function getBannerAll()
    {
        
        $this->db->from('frontendUsers');
        // $this->db->where(array('show' => 1));
        // $this->db->order_by('rank');
        $query = $this->db->get();
        return $query->result();
    }


    function checking(){

    	$userid = $this->session->userdata('userid');
    	$username = $this->session->userdata('username');
    	$fullName = $this->session->userdata('fullName');
    	$logged_in = $this->session->userdata('logged_in');
    	$secret = $this->session->userdata('secret');
    	$usertype = $this->session->userdata('usertype');

    	$passLogin=false;
    	if($usertype=="frontenduser"){
    		if($logged_in==false){
    			return false;
    		}
    		if(empty($userid)){
    			return false;
    		}
    		if(empty($secret)){
    			return false;
    		}
    		$this->db->where('id',$userid);
        	$this->db->where('secret',$secret);
        	if($this->db->get('frontendUsers')->row_array()){
        		$passLogin=true;
        		return true;
        	}	
        	else{
        		return false;
        	}

    	}//if($usertype=="frontenduser"){
    	if($usertype=="backenduser"){
    	    if($logged_in==false){
    			return false;
    		}
    		if(empty($userid)){
    			return false;
    		}
    		if(empty($secret)){
    			return false;
    		}
    		$this->db->where('id',$userid);
        	$this->db->where('secret',$secret);
        	if($this->db->get('adminUsers')->row_array()){
        		$passLogin=true;
        		return true;
        	}	
        	else{
        		return false;
        	}
    	
    	}
    }
    
     


 }