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

class Orderlist extends CI_Controller 
{

 public function __construct()
 {
  parent::__construct();
  $this->load->helper('url');
  $this->load->helper('form');
  $this->load->library("pagination");
  $this->load->model('Orderlist_model');
  $this->load->library('userauth');
}

public function list_order()
{
  $this->userauth->logged_in();
  $config = array();
  $config["base_url"] = base_url() . "admin/order-list";
  $total_row = $this->Orderlist_model->record_count();
  $config["total_rows"] = $total_row;
  $config["per_page"] = 20;
  $config['use_page_numbers'] = TRUE;
  $config['num_links'] = $total_row;
  $config['cur_tag_open'] = '<a class="current">';
  $config['cur_tag_close'] = '</a>';
  $config['next_link'] = '&raquo;';
  $config['prev_link'] = '&laquo;';

  $this->pagination->initialize($config);
  if($this->uri->segment(3)){
    $page = ($this->uri->segment(3)) ;
  }
  else{
    $page = 0;
  }
  $data["all_order"] = $this->Orderlist_model->get_order($config["per_page"], $page);

  $str_links = $this->pagination->create_links();
  $data["links"] = explode('&nbsp;',$str_links );
  $this->load->view('admin/order-list',$data);
}

public function order_search()
{
  $orderno      = $this->input->post('orderno');
  $fromedate    = date("Y-m-d",strtotime($this->input->post('fromedate')));
  $todate       = date("Y-m-d",strtotime($this->input->post('todate')));
  $data['all_order'] = $this->Orderlist_model->ordersearch($orderno,$fromedate,$todate);
  if($data['all_order']==array())
  {
    $this->session->set_flashdata('error_msg','No Order For The Given Data.');
    redirect('admin/order-list');
  }
  $str_links = $this->pagination->create_links();
  $data["links"] = explode('&nbsp;',$str_links );
  $this->load->view('admin/order-list',$data);
}

public function review_orderList($reg_id,$type)
{  
  $this->userauth->logged_in();
  $master = $this->Orderlist_model->review_order($reg_id);
  $data['return_class']=$this->Orderlist_model->return_class($reg_id);
  $data['member']=$this->Orderlist_model->returnAttende('tbl_attendee','reg_id','reg_m_type',$reg_id,'M');
  $data['member2']=$this->Orderlist_model->returnAttende('tbl_attendee','reg_id','reg_m_type',$reg_id,'M2');
  $data['nonmember']=$this->Orderlist_model->returnAttende('tbl_attendee','reg_id','reg_m_type',$reg_id,'N');
  $data['nonmember2']=$this->Orderlist_model->returnAttende('tbl_attendee','reg_id','reg_m_type',$reg_id,'N2');
  $data['semember']=$this->Orderlist_model->returnAttende('tbl_attendee','reg_id','reg_m_type',$reg_id,'S');
  $data['mcount'] = count($data['member']);
  $data['mcount2'] = count($data['member2']);
  $data['ncount'] = count($data['nonmember']);
  $data['ncount2'] = count($data['nonmember2']);
  $data['scount'] = count($data['semember']);

  $data['reg_date'] = date("d-m-Y",strtotime($master->reg_date));
  $data['card_holder_name'] = $master->card_holder_name;
  $data['payment_type'] = $master->payment_type;
  $data['address'] = $master->street_adrs;
  $data['phone_no'] = $master->phone_no;
  $data['email_id'] = $master->email_id;
  $data['class_count'] = $master->reg_class_count;
  $data['att_count'] = $master->att_total_count;
  $data['card_number'] = $master->card_number;
  $data['card_type'] = $master->card_type;
  $data['status'] = $master->status;



  $data['reg_total'] = $master->reg_total;
  $data['orderno'] = $master->reg_id;


  $data['type'] = $type;
  $this->load->view('admin/view-order',$data);
}

public function delete_list($reg_id)
{  
 $delete_list = $this->Orderlist_model->delete_list($reg_id);
 if($delete_list)
 {
  $this->session->set_flashdata('success_msg','Order Deleted Successfully');
  redirect('admin/order-list');
}
else 
{
  $this->session->set_flashdata('error_msg','Error Occur');
  redirect('admin/order-list');
}
}

function update_status($reg_id)
{
  $return_reg = $this->Orderlist_model->return_reg($reg_id);
  if($return_reg->status == "unpaid")
  {
   $update = $this->Orderlist_model->update_status("paid",$reg_id);  
   if($update)
   {
    $this->session->set_flashdata('success_msg','Updated Successfully');
    redirect('admin/order-list');
  }
  else 
  {
    $this->session->set_flashdata('error_msg','Error Occur');
    redirect('admin/order-list');
  }
}else
{
  $this->session->set_flashdata('error_msg','Already Paid');
  redirect('admin/order-list');
}
}

}

?>
