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

class Orderlist_model extends CI_model{

  public function record_count() 
  {
    return $this->db->count_all("tbl_regmaster");
  }

  public function get_order($limit,$start)
  {
   $this->db->select('*');
   $this->db->from('tbl_regmaster');
   $this->db->join('tbl_regclass', 'tbl_regclass.reg_id = tbl_regmaster.reg_id');
   $this->db->join('tbl_classform', 'tbl_classform.form_id = tbl_regclass.form_id');
   $this->db->join('tbl_classlocations', 'tbl_classlocations.locat_id = tbl_classform.locat_id');
   $this->db->group_by('tbl_regmaster.reg_id');
   $this->db->order_by('tbl_regmaster.reg_id','desc');
   $this->db->limit($limit, $start);
   $query = $this->db->get();
   return $query->result();
 }
//search
 public function ordersearch($orderno,$fromedate,$todate) 
 {
  $this->db->select('*');
  $this->db->from('tbl_regmaster');
  $this->db->join('tbl_regclass', 'tbl_regclass.reg_id = tbl_regmaster.reg_id');
  $this->db->join('tbl_classform', 'tbl_classform.form_id = tbl_regclass.form_id');
  $this->db->join('tbl_classlocations', 'tbl_classlocations.locat_id = tbl_classform.locat_id');
  $this->db->group_by('tbl_regmaster.reg_id');
  $this->db->order_by('tbl_regmaster.reg_id','desc');
  if($orderno)
  {
    $this->db->where('tbl_regmaster.reg_id',$orderno);
  }
  elseif($fromedate !="1970-01-01" && $todate !="1970-01-01")
  {
    $this->db->where('tbl_regmaster.reg_date >=', $fromedate);
    $this->db->where('tbl_regmaster.reg_date <=', $todate);
  }
  elseif($fromedate && $todate =="1970-01-01")
  {
    $this->db->where('tbl_regmaster.reg_date >=', $fromedate);
  }
  elseif($fromedate =="1970-01-01" && $todate)
  {
   $this->db->where('tbl_regmaster.reg_date <=', $todate);
 }
 $result=$this->db->get();
 return $result->result();

}

  //review_order
function review_order($reg_id)
{
  $this->db->from('tbl_regmaster'); 
  $this->db->where('reg_id',$reg_id);
  return $this->db->get()->row();
}

function return_class($reg_id)
{
  $this->db->from('tbl_regclass AS A'); 
  $this->db->join('tbl_classform AS B', 'A.form_id = B.form_id', 'INNER'); 
  $this->db->join('tbl_classname AS C', 'B.class_id = C.class_id', 'INNER'); 
  $this->db->join('tbl_classlocations AS D', 'B.locat_id = D.locat_id', 'INNER'); 
  $this->db->join('tbl_instructors AS E', 'B.instr_id = E.instr_id', 'INNER');
  $this->db->where('reg_id',$reg_id);
  return $this->db->get()->result_array();
}

function returnAttende($table='',$field1='',$field2='',$reg_id='',$type='')
{
  $this->db->from($table); 
  $this->db->where($field1,$reg_id);
  $this->db->where($field2,$type);
  return $this->db->get()->result_array();
}

function delete_list($reg_id)
{
 $tables = array('tbl_regmaster', 'tbl_regclass', 'tbl_attendee');
 $this->db->where('reg_id',$reg_id);
 $this->db->delete($tables);
 return true;
}

function return_reg($reg_id)
{
  $this->db->from('tbl_regmaster');
  $this->db->where('reg_id',$reg_id);
  return $this->db->get()->row();
}

function update_status($status,$reg_id)
{
  $this->db->where('reg_id',$reg_id );
  $this->db->set('status',$status);
  $this->db->update('tbl_regmaster');
  return true;
}


}
?>
