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

class inviteinevent_model extends CI_Model 
{

	function __construct()
    {
        parent::__construct();
        
    }
    function inviteinevent_details($eventid){ 
        $this->db->select('inviteevent.contactid,inviteevent.event,sum(inviteevent.adult) as tadult,sum(inviteevent.child) as tchild,sum(inviteevent.total) as ftotal,c.address,c.name');
        $this->db->from('inviteinevent as inviteevent');
        $this->db->join('contact as c','c.id=inviteevent.contactid','LEFT');  
        $this->db->where('inviteevent.status','1');
        $this->db->where('inviteevent.is_delete','0');
        $this->db->like('inviteevent.event',$eventid);
        $this->db->where('c.status','1');
        $this->db->where('c.is_delete','0');
        //$this->db->group_by('c.address');
        $query=$this->db->get();
        return $query->row_array();
    }
    function eventwiseview($eventid){ 
        $this->db->select('c.categoryid,c.name,c.address,c.city,c.mobile,e.adult,e.child,e.total,e.id,e.vehicle,e.room,e.roomdate,e.route');
        $this->db->from('inviteinevent as e');
        $this->db->join('contact as c','c.id=e.contactid','LEFT');  
        $this->db->where('e.status','1');
        $this->db->where('e.is_delete','0');
        if($eventid!=''){
           $this->db->where('e.event',$eventid);
        }else{
            $this->db->where('e.event',$eventid);
        }
        $this->db->where('c.status','1');
        $this->db->where('c.is_delete','0');
        $this->db->order_by('c.name','asc');
        $query=$this->db->get();
        return $query->result_array();
    }
   
    function addinviteinevent($data){
        $this->db->insert('inviteinevent', $data);
        return $this->db->insert_id();
    }
    function check_already_inviteinevent($name){
        $this->db->select('name');
        $this->db->from('inviteinevent');
        $this->db->where('name', $name);
        $query = $this->db->get();
        $numr =$query->num_rows();
        return $numr;
    }
    function editinviteinevent($data){
        $this->db->update("inviteinevent", $data, array('id' => $data['id']));
        return $this->db->affected_rows();
    }
    function invite_contact_delete($data){
        $this->db->update("inviteinevent", $data, array('contactid' => $data['contactid']));
        return $this->db->affected_rows();
    }
    function single_inviteinevent_details($inviteineventid){ 
        $this->db->select('*');
        $this->db->from('inviteinevent');
        $this->db->where('status','1');
        $this->db->where('is_delete','0');
        $this->db->where("id", $inviteineventid);
        $query=$this->db->get();
        return $query->row_array();
    }
    function get_inviting_list($eventid){ 
        //count(inviteevent.id) as cid
        $this->db->select('inviteevent.event,sum(inviteevent.adult) as tadult,sum(inviteevent.child) as tchild,sum(inviteevent.total) as ftotal,count(inviteevent.id) as cid');
        $this->db->from('inviteinevent as inviteevent');
        $this->db->join('contact as c','c.id=inviteevent.contactid','LEFT');  
        $this->db->where('inviteevent.status','1');
        $this->db->where('inviteevent.is_delete','0');
        $this->db->where('inviteevent.event',$eventid);
        $this->db->where('c.status','1');
        $this->db->where('c.is_delete','0');
        $query=$this->db->get();
        return $query->row_array();
    }
    function reportdetailview($data){ 
        $this->db->select('c.categoryid,c.name,c.address,c.city,c.mobile,e.adult,e.child,e.total,e.id,e.vehicle,e.room,e.roomdate,e.route');
        $this->db->from('inviteinevent as e');
        $this->db->join('contact as c','c.id=e.contactid','LEFT');    
        $this->db->where('e.status','1');
        $this->db->where('e.is_delete','0');
        if($data['eventid']!=''){
           $this->db->where('e.event',$data['eventid']);
        }else{
            $this->db->where('e.event',$data['eventid']);
        }
        if($data['vehicle']!=''){
            $this->db->where('e.vehicle',$data['vehicle']);
        }
        if($data['roomdate']!=''){
            $this->db->where('e.roomdate',$data['roomdate']);
        }
        if($data['route']!=''){
            $this->db->where('e.route',$data['route']);
        }
        if($data['hotel']!=''){
            $this->db->where('e.hotel',$data['hotel']);
        }
        $this->db->where('c.status','1');
        $this->db->where('c.is_delete','0');
        $query=$this->db->get();
        return $query->result_array();
    }
    function check_invite($contactid){
        $this->db->select('');
        $this->db->from('inviteinevent');
        $this->db->where('contactid', $contactid);
        $this->db->where('status','1');
        $this->db->where('is_delete','0');
        $query = $this->db->get();
        return $query->row_array();
    }
    // New Invite
    function contact_record_count($passdeta) {
        $this->db->where('status','1');
        $this->db->where('is_delete','0');
        if($passdeta['categoryid']!=''){
            $categoryid=$passdeta['categoryid'];
            $this->db->where('categoryid LIKE', '%'.$categoryid.'%');
        }
        if($passdeta['name']!=''){
            $name=$passdeta['name'];
            $this->db->where("`name` LIKE '%$name%'"); 
        }
        if($passdeta['city']!=''){
            $city=$passdeta['city'];
            $this->db->where("`city` LIKE '%$city%'"); 
        }
        if($passdeta['mobile']!=''){
            $mobile=$passdeta['mobile'];
            $this->db->where("`mobile` LIKE '%$mobile%'"); 
        }
        if($passdeta['address']!=''){
            $address=$passdeta['address'];
            $this->db->where("`address` LIKE '%$address%'"); 
        }
        return $this->db->count_all_results("contact");

    }
    function contact_record_fetch($passdeta){ 
        $this->db->select('c.categoryid,c.name,c.address,c.city,c.mobile,c.email,c.id,cat.name as catname');
        $this->db->from('contact as c');
        $this->db->join('category as cat','cat.id=c.categoryid','LEFT');  
        $this->db->where('c.status','1');
        $this->db->where('c.is_delete','0');
        if($passdeta['categoryid']!=''){
           $categoryid=$passdeta['categoryid'];
           $this->db->where('c.categoryid LIKE', '%'.$categoryid.'%');
        }
        if($passdeta['name']!=''){
            $name=$passdeta['name'];
            $this->db->where("`c.name` LIKE '%$name%'"); 
        }
        if($passdeta['city']!=''){
            $city=$passdeta['city'];
            $this->db->where("`c.city` LIKE '%$city%'"); 
        }
        if($passdeta['mobile']!=''){
            $mobile=$passdeta['mobile'];
            $this->db->where("`c.mobile` LIKE '%$mobile%'"); 
        }
        if($passdeta['address']!=''){
            $address=$passdeta['address'];
            $this->db->where("`c.address` LIKE '%$address%'"); 
        }
        $this->db->order_by("c.name", "asc");
        $this->db->limit($passdeta['limit'],$passdeta['start']);
        $query=$this->db->get();
        return $query->result_array();
      
    }
    function checkevent($contactid,$event){
        $this->db->select('');
        $this->db->from('inviteinevent');
        $this->db->where('contactid', $contactid);
        $this->db->where('event', $event);
        $this->db->where('status','1');
        $this->db->where('is_delete','0');
        $query = $this->db->get();
        return $query->row_array();
    }
    // Invite updates
    function record_count($passdeta) {
        $this->db->select('e.id');
        $this->db->from('inviteinevent as e');
        $this->db->join('contact as c','c.id=e.contactid','LEFT');  
        $this->db->where('e.status','1');
        $this->db->where('e.is_delete','0');
        $this->db->where('c.status','1');
        $this->db->where('c.is_delete','0');
        if($passdeta['categoryid']!=''){
            $categoryid = $passdeta['categoryid'];
            $this->db->where('c.categoryid LIKE', '%'.$categoryid.'%');
        }
        if($passdeta['name']!=''){
            $name=$passdeta['name'];
            $this->db->where("`c.name` LIKE '%$name%'"); 
        }
        if($passdeta['address']!=''){
            $address=$passdeta['address'];
            $this->db->where("`c.address` LIKE '%$address%'"); 
        }
        if($passdeta['city']!=''){
            $city=$passdeta['city'];
            $this->db->where("`c.city` LIKE '%$city%'"); 
        }
        if($passdeta['mobile']!=''){
            $mobile=$passdeta['mobile'];
            $this->db->where("`c.mobile` LIKE '%$mobile%'"); 
        }
        if($passdeta['eventid']!=''){
            $eventid=$passdeta['eventid'];
            $this->db->where('e.event',$eventid);
        }
        $this->db->order_by('c.name','asc');
        $query=$this->db->get();
        
        return $query->result_array();
    }
    function record_fetch($passdeta){ 
        $this->db->select('c.categoryid,c.name,c.address,c.city,c.mobile,e.adult,e.child,e.total,e.id,e.vehicle,e.room,e.roomdate,e.route,e.contactid,e.event,e.hotel');
        $this->db->from('inviteinevent as e');
        $this->db->join('contact as c','c.id=e.contactid','LEFT');  
        $this->db->where('e.status','1');
        $this->db->where('e.is_delete','0');
        $this->db->where('c.status','1');
        $this->db->where('c.is_delete','0');
        if($passdeta['categoryid']!=''){
            $categoryid = $passdeta['categoryid'];
            $this->db->where('c.categoryid LIKE', '%'.$categoryid.'%');
        }
        if($passdeta['name']!=''){
            $name=$passdeta['name'];
            $this->db->where("`c.name` LIKE '%$name%'"); 
        }
        if($passdeta['address']!=''){
            $address=$passdeta['address'];
            $this->db->where("`c.address` LIKE '%$address%'"); 
        }
        if($passdeta['city']!=''){
            $city=$passdeta['city'];
            $this->db->where("`c.city` LIKE '%$city%'"); 
        }
        if($passdeta['mobile']!=''){
            $mobile=$passdeta['mobile'];
            $this->db->where("`c.mobile` LIKE '%$mobile%'"); 
        }
        if($passdeta['eventid']!=''){
            $eventid=$passdeta['eventid'];
            $this->db->where('e.event',$eventid);
        }
        $this->db->order_by('c.name','asc');
        $this->db->limit($passdeta['limit'],$passdeta['start']);
        $query=$this->db->get();
        //echo $this->db->last_query();
        return $query->result_array();
    }
    function record_total($passdeta) {
        $this->db->select('e.event,sum(e.adult) as tadult,sum(e.child) as tchild,sum(e.total) as ftotal,count(e.id) as cid');
        $this->db->from('inviteinevent as e');
        $this->db->join('contact as c','c.id=e.contactid','LEFT');  
        $this->db->where('e.status','1');
        $this->db->where('e.is_delete','0');
        $this->db->where('c.status','1');
        $this->db->where('c.is_delete','0');
        if($passdeta['categoryid']!=''){
            $categoryid = $passdeta['categoryid'];
            $this->db->where('c.categoryid LIKE', '%'.$categoryid.'%');
        }
        if($passdeta['name']!=''){
            $name=$passdeta['name'];
            $this->db->where("`c.name` LIKE '%$name%'"); 
        }
        if($passdeta['address']!=''){
            $address=$passdeta['address'];
            $this->db->where("`c.address` LIKE '%$address%'"); 
        }
        if($passdeta['city']!=''){
            $city=$passdeta['city'];
            $this->db->where("`c.city` LIKE '%$city%'"); 
        }
        if($passdeta['mobile']!=''){
            $mobile=$passdeta['mobile'];
            $this->db->where("`c.mobile` LIKE '%$mobile%'"); 
        }
        if($passdeta['eventid']!=''){
            $eventid=$passdeta['eventid'];
            $this->db->where('e.event',$eventid);            
        }        
        $query=$this->db->get();
        //echo $this->db->last_query();
        return $query->row_array();
    }
    //
    function invite_totalrecord(){ 
        $this->db->select('c.categoryid,c.name,c.address,c.city,c.mobile,e.adult,e.child,e.total,e.id,e.vehicle,e.room,e.roomdate,e.route');
        $this->db->from('inviteinevent as e');
        $this->db->join('contact as c','c.id=e.contactid','LEFT');  
        $this->db->where('e.status','1');
        $this->db->where('e.is_delete','0');
        $this->db->where('c.status','1');
        $this->db->where('c.is_delete','0');
        $this->db->group_by('e.contactid');
        $this->db->order_by('c.name','asc');
        $query=$this->db->get();
        return $query->result_array();
    }
    // All in One
    function allinone_record_fetch($passdeta){ 
        $this->db->select('c.categoryid,c.name,c.address,c.city,c.mobile,e.contactid');
        $this->db->from('inviteinevent as e');
        $this->db->join('contact as c','c.id=e.contactid','LEFT');  
        $this->db->where('e.status','1');
        $this->db->where('e.is_delete','0');
        $this->db->where('c.status','1');
        $this->db->where('c.is_delete','0');
        if($passdeta['categoryid']!=''){
            $categoryid = $passdeta['categoryid'];
            $this->db->where('c.categoryid LIKE', '%'.$categoryid.'%');
        }
        if($passdeta['name']!=''){
            $name=$passdeta['name'];
            $this->db->where("`c.name` LIKE '%$name%'"); 
        }
        if($passdeta['address']!=''){
            $address=$passdeta['address'];
            $this->db->where("`c.address` LIKE '%$address%'"); 
        }
        if($passdeta['city']!=''){
            $city=$passdeta['city'];
            $this->db->where("`c.city` LIKE '%$city%'"); 
        }
        if($passdeta['mobile']!=''){
            $mobile=$passdeta['mobile'];
            $this->db->where("`c.mobile` LIKE '%$mobile%'"); 
        }
        if($passdeta['eventid']!=''){
            $eventid=$passdeta['eventid'];
            $this->db->where('e.event',$eventid);
        }
        $this->db->order_by('c.name','asc');
        if($passdeta['limit']!='' and $passdeta['start']!=''){
            $this->db->limit($passdeta['limit'],$passdeta['start']);
        }
        $this->db->group_by('e.contactid');
        $query=$this->db->get();
        //echo $this->db->last_query();
        return $query->result_array();
    }
    function allinone_checkevent($contactid){
        $this->db->select('e.*,ev.name as eventname');
        $this->db->from('inviteinevent as e');
        $this->db->where('e.contactid', $contactid);
        $this->db->join('event as ev','ev.id=e.event','LEFT'); 
        $this->db->where('e.status','1');
        $this->db->where('e.is_delete','0');
        $this->db->order_by('e.event','asc');
        $query = $this->db->get();

        return $query->result_array();
    }
    
       
}
?>
