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

class Duty_Model extends CI_Model {
	public function insert(){
		$data=array("office_name"=>$_POST['office_name'],
					"guard_name"=>$_POST['guard_name'],
				// 	"assign_date"=>$_POST['assign_date'],
					 "inserted_SI"=>$this->session->userdata('id'),
                       "inserted_by"=>$this->session->userdata('name'),
                       "inserted_DT"=>date('Y-m-d H:i:s')
				);
		$this->db->insert('tr_assign_duty',$data);
		//return $this->db->last_query();
	}

	public function fetch_data()
	{
	 	$this->db->select('tad.*,mst_office.name as o_name,mst_guard.name,mst_hospital.hos_name as hosname');
	 	$this->db->where('tad.deleted_DT',NULL);
		$this->db->from('tr_assign_duty tad');
		$this->db->join('mst_office','mst_office.id=tad.office_name','left');
		$this->db->join('mst_hospital','mst_hospital.hos_id=tad.office_name','left');
		$this->db->join('mst_guard','mst_guard.id=tad.guard_name','left');
		$this->db->order_by("tad.d_id","desc");
		return $query=$this->db->get()->result();
	}

	public function display_duty_recordsById($id)
	{
		$query=$this->db->query("select * from tr_assign_duty where d_id='".$id."'");

		return $query->result();
	}

	public function update($id)
	{
	/*	$n=$this->input->post('office_name');
		$a=$this->input->post('guard_name');		
		$query=$this->db->query("update tr_assign_duty SET office_name='$n',guard_name='$a' where d_id='".$id."'");*/
		
		$data=array("office_name"=>$_POST['office_name'],
					   "guard_name"=>$_POST['guard_name'],
					   //"assign_date"=>$_POST['assign_date'],
					   "Modify_SI"=>$this->session->userdata('id'),
                   	 "modify_by"=>$this->session->userdata('username'),
                    "Modify_DT"=>date('Y-m-d H:i:s'));
       				 $c=$this->db->where('d_id',$id)->update('tr_assign_duty',$data);

	}

public function fetch_office_name()
	{
	    
	//	$query=$this->db->query("select name,id as officeid from mst_office");
			//$this->db->where('tr_assign_duty.deleted_DT',NULL);
	//	return $query->result();
		//return $this->db->last_query();
		$this->db->select('id as officeid ,name'); 
	    $this->db->where('deleted_DT',NULL);
  	    $this->db->from('mst_office');
  	    $this->db->order_by('id',"desc");
 	    $query = $this->db->get();
    	return $query->result();
	}

	public function fetch_guard_name()
	{
		//$query=$this->db->query("select name,id from mst_guard");
	//	return $query->result();
		//return $this->db->last_query();
		$this->db->select('id ,name'); 
	    $this->db->where('deleted_DT',NULL);
  	    $this->db->from('mst_guard');
  	    $this->db->order_by('id',"desc");
 	    $query = $this->db->get();
  	    return $query->result();
	}
	
	public function get_patient()
	{
	    $this->db->select('mst.id ,mst.name,mst.patient_status');
	    $this->db->where('msd.transfer_status',NULL);
	    $this->db->join('tr_assign_duty msd','mst.id=msd.guard_name');
	   // $this->db->where('mst.deleted_DT',NULL);
	             
  	    $this->db->from('mst_guard mst');
  	    $this->db->order_by('mst.id',"desc");
 	    $query = $this->db->get();
  	    return $query->result();
	}
	
	
	public function get_all_patient()
	{
	    $this->db->select('mst.id ,mst.name,mst.patient_status');
	    $this->db->where('mst.deleted_DT',NULL);
	             
  	    $this->db->from('mst_guard mst');
  	    $this->db->order_by('mst.id',"desc");
 	    $query = $this->db->get();
  	    return $query->result();
	}
	

	public function get_positive_patient()
	{
	    $this->db->select('mst.id ,mst.name, mst.patient_status');
	    $this->db->where('(mst.patient_status = 1)');
	   // $this->db->join('tr_assign_duty msd','mst.id=msd.guard_name');
	    $this->db->where('mst.deleted_DT',NULL);
	   // $this->db->or_where('(mst.deleted_DT IS NOT NULL AND mst.deactive_cronjob_flag = 1)');
  	    $this->db->from('mst_guard mst');
  	    $this->db->order_by('mst.id',"desc");
 	    $query = $this->db->get();
  	    return $query->result();
	}
	
	
	public function get_patient_status()
	{
	    $this->db->select('mst.id ,mst.name');
	  //  $this->db->where('msd.transfer_status',NULL);
	    $this->db->join('tr_assign_duty msd','mst.id=msd.guard_name');
	    $this->db->where('mst.deleted_DT',NULL);
  	    $this->db->from('mst_guard mst');
  	    $this->db->order_by('mst.id',"desc");
 	    $query = $this->db->get();
  	    return $query->result();
	}
	
	
	public function get_patient2()
	{
	    $this->db->select('mst.id ,mst.name');
	    $this->db->join('tr_assign_duty msd','mst.id=msd.guard_name');
	    $this->db->where('mst.deleted_DT',NULL);
	     $this->db->or_where('(mst.deleted_DT IS NOT NULL AND mst.deactive_cronjob_flag = 1)');
	   // $this->db->where('mst.Transfer_status',NULL);
  	    $this->db->from('mst_guard mst');
  	    $this->db->order_by('mst.id',"desc");
 	    $query = $this->db->get();
  	    return $query->result();
	}
	
	public function fetch_data_status()
	{
	 	$this->db->select('tad.*,mst_office.name as o_name,mst_guard.name,mst_guard.id,mst_hospital.hos_name as hosname,tad.transfer_status as status');
	 	$this->db->where('tad.deleted_DT',NULL);
	 	$this->db->where('tad.transfer_status!=','NULL');
		$this->db->from('tr_assign_duty tad');
		$this->db->join('mst_office','mst_office.id=tad.office_name','left');
		$this->db->join('mst_hospital','mst_hospital.hos_id=tad.office_name','left');
		$this->db->join('mst_guard','mst_guard.id=tad.guard_name','left');
		$this->db->order_by("tad.d_id","desc");
		return $query=$this->db->get()->result();
	}
	
	
}
