<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of accountmodel
 *
 * @author BusyMan
 */
class NotificationsetupModel extends CI_Model {

    //put your code here
    private $_tbl_NOT = 'tbl_notification';
    private $_tbl_NOTR='tbl_notification_receiver';
    private $_tbl_user = 'tbl_user';
    
    public function saveNotification($datan){
        $this->db->insert($this->_tbl_NOT,$datan);
        return $this->db->insert_id();
    }
    public function  getReceiver(){
        $query=$this->db->select('userId')->get_where($this->_tbl_user,array('userType'=>1));
        $result=$query->result_array();
    	if(!empty($result))
    	{
    		return $result;
    	}
    }
    
    public function saveReceiverNotification($datar){
        $this->db->insert($this->_tbl_NOTR,$datar);
    }
    
    /*public function countNotification(){
        $data['receiver']=$this->session->userdata('employeeId');
         $query=$this->db->get_where($this->_tbl_NOTR,array('receiver'=>$data['receiver'],'status'=>0));
         return $query->num_rows();
//         $result=$query->result_array();
//         if(!empty($result)){return $result;}
        
    }*/
    
    public function getNotification(){
        {
            $data['receiver']=$this->session->userdata('employeeId');
            $this->db->select('tblNor.*,tblNo.*');
            $this->db->from('tbl_notification tblNo');
            $this->db->join('tbl_notification_receiver tblNor','tblNo.notification_id=tblNor.notification_id');
            $this->db->where('tblNor.receiver',$data['receiver']);
            $this->db->where('tblNor.status',0);
            //$this->db->where('tblNo.date',date('Y-m-d'));
            $this->db->order_by('tblNo.notification_id','DESC');
            $query=$this->db->get();
            $result=$query->result_array();
            if(!empty($result))
            {
            return $result;
            }

            }
        }

        public function updateStatus($Id)
        {
            $data['status']=1;
            $query=$this->db->update($this->_tbl_NOTR,$data,array('receiver'=>$Id));
            return $this->db->affected_rows();
        }


        public function getlandCustomerslIdById($customerId){
            $query  = $this->db->select('id')->get_where('tbl_customer_reg', array('customerId'=>$customerId));
            $result = $query->result_array();
            if(!empty($result)) {
                return $result;
            }
        }
    
    
}

