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

class Customer_model extends CI_Model{
	
	public function add_customer($data) {
		$customerins = $data;
		if(isset($data['c_pwd'])) {
			$customerins['c_pwd'] = md5($data['c_pwd']); 
		}
		return	$this->db->insert('customers',$customerins);
	} 
    public function getall_customer() { 
		//return $this->db->select('*')->from('customers')->order_by('c_id','desc')->get()->result_array();

		$organization_id=$this->session->userdata['session_data']['organization_id'];
		$this->db->select("*");
		$this->db->from('trips');
		$this->db->join('drivers', 'drivers.d_id=trips.t_driver');
		$this->db->join('customers', 'customers.c_id=trips.t_customer_id');
		$this->db->where('drivers.organization_id',$organization_id);
		$this->db->group_by('customers.c_id'); 
		$query = $this->db->get();
		return $query->result_array();


	} 
	public function getall_feedback() { 
		//return $this->db->select('*')->from('customers')->order_by('c_id','desc')->get()->result_array();

		$organization_id=$this->session->userdata['session_data']['organization_id'];
		$this->db->select("*");
		$this->db->from('feedback_customers');
		$this->db->join('drivers', 'drivers.d_id=feedback_customers.f_d_id');
		$this->db->join('customers', 'customers.c_id=feedback_customers.f_c_id');

		$this->db->where('drivers.organization_id',$organization_id);
		 
		$query = $this->db->get();
		return $query->result_array();


	} 
	public function get_feedback($f_id) { 
		return $this->db->select('*')->from('feedback_customers')->where('f_id',$f_id)->get()->result_array();
		
	} 
	public function getall_support() { 
		return $this->db->select('*')->from('support_customers')->join('customers', 'customers.c_id=support_customers.s_c_id')->order_by('su_id','desc')->get()->result_array();

		// $organization_id=$this->session->userdata['session_data']['organization_id'];
		// $this->db->select("*");
		// $this->db->from('feedback_customers');
		// $this->db->join('drivers', 'drivers.d_id=feedback_customers.f_d_id');
		// $this->db->join('customers', 'customers.c_id=feedback_customers.f_c_id');

		// $this->db->where('drivers.organization_id',$organization_id);
		 
		// $query = $this->db->get();
		// return $query->result_array();


	}
	public function get_support($su_id) { 
		return $this->db->select('*')->from('support_customers')->join('customers', 'customers.c_id=support_customers.s_c_id')->where('su_id',$su_id)->get()->result_array();
		
	}
	public function get_customerdetails($c_id) { 
		return $this->db->select('*')->from('customers')->where('c_id',$c_id)->get()->result_array();
	} 
	public function update_customer() { 
		$this->db->where('c_id',$this->input->post('c_id'));
		return $this->db->update('customers',$this->input->post());
	}
} 