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

class Brcustomeradmin extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see https://codeigniter.com/user_guide/general/urls.html
	 */
         var $menu;
         var $contactus;
        public function __construct()
        {
            parent::__construct();
            $this->load->library(array('session'));
            // $this->load->model('Section', 'section_model');
            // $this->menu = $this->section_model->buildTopMenuItem();
            // $this->breadcrumbs = [];
            // $this->load->model('ContactDetails', 'contactdetails_model');
            // $this->contactus = $this->contactdetails_model->getContactus();

            $this->load->model('Brcustomermodel', 'customer_model');
            $this->load->model('Brshopmodel', 'shop_model');
            $this->load->model('LivingareaModel', 'livingarea_model');
             $this->load->model('BrservicesModel', 'services_model');
            $this->load->model('Bremployeemodel', 'employee_model'); 
            $this->load->model('Brcustomerlevelmodel', 'customerlevel_model'); 
            $this->load->model('Brchannelmodel', 'channel_model'); 
             $this->load->model('BrservicesuserModel', 'servicesuser_model');
             $this->load->model('BrBookingModel', 'booking_model');
             $this->load->model('Brcustomerbodymodel', 'customerbody_model');
             $this->load->model('Brcustomerfacemodel', 'customerface_model');
             $this->load->model('Brcustomerpointmodel', 'customerpoint_model');
             $this->load->model('Brcustomerusedpointmodel', 'customerusedpoint_model');
            if (!$this->session->userdata('logged_in'))
            { 
                redirect('/at-cms/login');
            }
    
            
            $this->load->helper('form');
            
        }

        public function index()
	{

        $userid = $this->session->userdata('userid');
        // $user_data = $this->session->userdata('USER_ID');

        if(empty($userid)){
            // $this->load->view('test1');
            redirect('/at-cms/login', 'refresh');
        }
        $this->load->helper('url');
        //testing
        // $currentURL = current_url(); //for simple URL
        // $params = $_SERVER['QUERY_STRING']; //for parameters
        // $fullURL = $currentURL . '?' . $params; //full URL with parameter
        //end testing


        //for pagination    
         // or you can autoload it in config

// print base_url($this->uri->uri_string());
        // $config["base_url"] = base_url() . "adminmain/index/";
        $config["base_url"] =  base_url() ."at-cms/folderadmin/index";
        // $config["total_rows"] = $this->Countries->record_count();
        
        // $config["total_rows"] = $this->shop_model->record_count();
        
        $config["uri_segment"] = 4;
        $config["per_page"] = 10;
        $config["page"] = 0;

        // $page = ($this->uri->segment(3))? $this->uri->segment(3) : 0;

        $this->load->helper('url');
        if(!empty($this->uri->segment(4))){
            $page = $this->uri->segment(4);  
        }
        else{
            $page = $config["page"];
        }
        // get 11
        if(!empty($this->uri->segment(5))){
            $perpage = $this->uri->segment(5);  
        }
        else{
            $perpage = $config["per_page"];
        }
        // $perpage = $this->uri->segment(4);

        // $choice = $config["total_rows"] / $perpage;
        // $config["num_links"] = round($choice);
        // $config["num_links"] = ceil($choice);
        
        //end for pagination

        // $this->load->view('welcome_message');
        $data = array(
                'title' => 'My Title',
                'heading' => 'My Heading',
                'message' => 'My Message'
            );        
        // $data['total_rows']=$config["total_rows"];
        $data['page']=$page;
        $data['perpage']=$perpage;
        // $data['num_links'] = $config["num_links"];
        // $data['record']=$this->folder_model->getfolderdata($perpage, $page);
        $data['base_url'] =$config["base_url"];
        $data['fullName'] = $this->session->userdata('fullName');  
        $count=1;
        // foreach($data['record'] as $row){
        //     $data['level1'][$count]=$this->folder_model->getlevel1data($row->id);
        //     $data['level1Record'][$count]=$this->folder_model->getflodercount($row->id);
        //     $countLevel2=1;
        //     foreach($data['level1'][$count] as $secondrow){
        //         $data['level2'][$count][$countLevel2]=$this->folder_model->getlevel2data($secondrow->id);
        //         $countLevel3=1;
        //         foreach($data['level2'][$count][$countLevel2] as $thirdrow){
        //             $data['level3'][$count][$countLevel2][$countLevel3]=$this->folder_model->getlevel3data($thirdrow->id);
        //             $countLevel3=$countLevel3+1;
        //         }
        //         $countLevel2=$countLevel2+1;
        //     }
        //     $count++;

        // }
        
        //for side bar menu
            $data['shop']=$this->shop_model->getAllShop();
            $data['currentshop']= $this->session->userdata('currentshop');
            //end for side bar menu

        //get all shop data
        $data["shop_list"] = $this->shop_model->getShopAll();

        //end get all shop data

        //add searching level

        $serachlevel= $this->session->userdata('searchlevel');   
        $channelSelectID= $this->session->userdata('channelSelectID'); 
         $searchmem= $this->session->userdata('searchmem');
        
        //end add searching level

        //added for bora sarah special id to see all shop customer 2020-11-03
         // if($this->session->userdata('userid')== '22' && $this->session->userdata('username')=='sarah'){

        // if($this->session->userdata('userid')== '22' && $this->session->userdata('username')=='sarah'){
       
        //     $data["customer_list"] = $this->customer_model->getCustomerAllShopWithSecondShop($this->session->userdata('currentshop'),$this->employee_model->getSecondShopid($this->session->userdata('userid')),$serachlevel,$channelSelectID,$searchmem);
        // }//if($this->session->userdata('userid')!= '22' && 
        //end added for bora sarah special id to see all shop customer


        //get customer data
        // if($this->session->userdata('userid')!= '22' && $this->session->userdata('username')!='sarah'){
        // $data["customer_list"] = $this->customer_model->getCustomerAll($this->session->userdata('currentshop'),$serachlevel,$channelSelectID,$searchmem);
        // }//if($this->session->userdata('userid')!= '22' && $this->session->userdata('username')!='sarah'){
        //end get customer data

        //get all member level
        $data["memberlevel_list"]=$this->customerlevel_model->getLevelAll();
        //end get all member level
            
        //get all channel model
        $data["channel_list"]=$this->channel_model->getChannelAll();
        //end get all channel model
        $data['selectedmenu']='brcustomeradmin';    

        $this->load->view('/admin/brcustomerview',$data);
        // $contactusdata = $this->contactdetails_model->getContactus();
        //     $this->breadcrumbs[] = array (
        //         'label' => '聯絡我們',
        //         'link' => ''
        //     );
        //     $this->twig->display('main', array(
        //         'path' => array(
        //             'vendor' => $this->config->item('vendor_path'),
        //             'script' => $this->config->item('script_path'),
        //             'css' => $this->config->item('css_path'),
        //             'image' => $this->config->item('image_path')
        //         ),
        //         'breadcrumbs' => $this->breadcrumbs,
        //         'menus' => $this->menu,
        //         'contactusdata'=>$contactusdata,
        //         'session' => 'contact',
        //         'contactus' => $this->contactus,
        //         'page' => 'index'
        //     ));
        }
        public function add(){
            $userid = $this->session->userdata('userid');
            // $user_data = $this->session->userdata('USER_ID');

            if(empty($userid)){
            // $this->load->view('test1');
                redirect('/at-cms/login', 'refresh');
            }
            $this->load->helper('url');

            //old data 
             $config["base_url"] =  base_url() ."at-cms/folderadmin/index";
            // $config["total_rows"] = $this->Countries->record_count();
            
            // $config["total_rows"] = $this->shop_model->record_count();
            
            $config["uri_segment"] = 4;
            $config["per_page"] = 10;
            $config["page"] = 0;

            // $page = ($this->uri->segment(3))? $this->uri->segment(3) : 0;

            $this->load->helper('url');
            if(!empty($this->uri->segment(4))){
                $page = $this->uri->segment(4);  
            }
            else{
                $page = $config["page"];
            }
            // get 11
            if(!empty($this->uri->segment(5))){
                $perpage = $this->uri->segment(5);  
            }
            else{
                $perpage = $config["per_page"];
            }
            // $perpage = $this->uri->segment(4);

            // $choice = $config["total_rows"] / $perpage;
            // $config["num_links"] = round($choice);
            // $config["num_links"] = ceil($choice);
            
            //end for pagination

            // $this->load->view('welcome_message');
            $data = array(
                    'title' => 'My Title',
                    'heading' => 'My Heading',
                    'message' => 'My Message'
                );        
            // $data['total_rows']=$config["total_rows"];
            $data['page']=$page;
            $data['perpage']=$perpage;
            // $data['num_links'] = $config["num_links"];
            // $data['record']=$this->folder_model->getfolderdata($perpage, $page);
            $data['base_url'] =$config["base_url"];
            $data['fullName'] = $this->session->userdata('fullName');  
            $count=1;

            //end old data

            //for side bar menu
            $data['shop']=$this->shop_model->getAllShop();
            $data['currentshop']= $this->session->userdata('currentshop');
            //end for side bar menu
            
             $data['pagemethod']='add';
             // $data['customercode']=$this->shop_model->getShopcode($this->session->userdata('currentshop'));
             $data['customercode']=$this->shop_model->getLastCustcode($this->session->userdata('currentshop'));

             $data['firstzone']=$this->livingarea_model->getFirstZone();
             $data['shopimprove']=$this->shop_model->getSkinImprove();  


             $data['bodyimprovelist']=$this->customerbody_model->getAll();

             $data['faceimprovelist']=$this->customerface_model->getAll();
              //get all shop data
            $data["shop_list"] = $this->shop_model->getShopAll();

            //end get all shop data

            //get all member level
            $data["memberlevel_list"]=$this->customerlevel_model->getLevelAll();
            //end get all member level

            //get all channel model
             $data["channel_list"]=$this->channel_model->getChannelAll();
            //end get all channel model

             $data["services"]=$this->services_model->getAllServices();

            //get customer service
             $data["customerService"]=array();
            //end get customer service

              $data['therapistlist']=$this->employee_model->getTheraphistAll($this->session->userdata('currentshop'));
            // $data="";
            $data['selectedmenu']='brcustomeradmin'; 

            $this->load->view('/admin/brcustomeraddview',$data);
        }
        public function edit(){
          
            $userid = $this->session->userdata('userid');
            // $user_data = $this->session->userdata('USER_ID');

            if(empty($userid)){
                // $this->load->view('test1');
                redirect('/at-cms/login', 'refresh');
            }
            $this->load->helper('url');
            $config["base_url"] =  base_url() ."adminmain/index";
        // $config["total_rows"] = $this->Countries->record_count();
        
        // $config["total_rows"] = $this->frontenduser_model->record_count();
        
        $config["uri_segment"] = 3;
        $config["per_page"] = 10;
        $config["page"] = 0;

        // $page = ($this->uri->segment(3))? $this->uri->segment(3) : 0;

        $this->load->helper('url');
        if(!empty($this->uri->segment(3))){
            $page = $this->uri->segment(3);  
        }
        else{
            $page = $config["page"];
        }
        // get 11
        if(!empty($this->uri->segment(4))){
            $perpage = $this->uri->segment(4);  
        }
        else{
            $perpage = $config["per_page"];
        }
        // $perpage = $this->uri->segment(4);

        // $choice = $config["total_rows"] / $perpage;
        // $config["num_links"] = round($choice);
        // $config["num_links"] = ceil($choice);
        
        //end for pagination

        // $this->load->view('welcome_message');
        $data = array(
                'title' => 'My Title',
                'heading' => 'My Heading',
                'message' => 'My Message'
            );        
        // $data['total_rows']=$config["total_rows"];
        $data['page']=$page;
        $data['perpage']=$perpage;
        // $data['num_links'] = $config["num_links"];
        // $data['record']=$this->frontenduser_model->getAdmindata($perpage, $page);
        $data['base_url'] =$config["base_url"];
        $data['fullName'] = $this->session->userdata('fullName'); 

         //employee group data
        // $data['employeegroup']=$this->employeegroup_model->getAllEmployeeGroup();

        $data['shop']=$this->shop_model->getShopAll();
        $data['services']=$this->services_model->getAllServices();
        // dump($data['services']);
        // $data['employeeincometype']=$this->employee_model->getEmployeeIncomeType();

        //set default current shop id,
        //it may be delete in later
        if(empty($this->session->userdata('currentshop'))){
            $this->session->set_userdata('currentshop', 1); 
        }
        //end 
        $data['pagemethod']='add';
        $data['currentshop']= $this->session->userdata('currentshop');
        $data['customercode']=$this->shop_model->getShopcode($this->session->userdata('currentshop'));
        $data['shopimprove']=$this->shop_model->getSkinImprove();

        $data['bodyimprovelist']=$this->customerbody_model->getAll();

        $data['faceimprovelist']=$this->customerface_model->getAll();


        $data['firstzone']=$this->livingarea_model->getFirstZone();

        //end 

        //get customer data
            $data['pagemethod']='edit';
            $id = $this->uri->segment(4);
            $data['customerdetails']=$this->customer_model->getCustomer($id);
            $data['customerdetailslivingarea']=$this->customer_model->getCustomerLivingArea($id);
            $data['customerdetailsPromotionCode']=$this->customer_model->getCustomerPromotionCode($id);
            $data['customerdetailsSkinImprove']=$this->customer_model->getCustomerSkinImprove($id);


            $data['customerdetailsBodyImprove']=$this->customer_model->getCustomerBodyImprove($id);
            $data['customerdetailsFaceImprove']=$this->customer_model->getCustomerFaceImprove($id);

            $userid = $this->session->userdata('userid');
            

            //get customer name

            $createrrow=$this->employee_model->getUserDetail($data['customerdetails']->created_by);
            $data['creator']=$createrrow;
            

             $updaterrow=$this->employee_model->getUserDetail($data['customerdetails']->updated_by);
            $data['updater']=$updaterrow;
            // var_dump($data['creator']);
            //end get customer name

             //get all shop data
        $data["shop_list"] = $this->shop_model->getShopAll();
        //end get customer data
        
            //get all member level
            $data["memberlevel_list"]=$this->customerlevel_model->getLevelAll();
            //end get all member level
            
             //get all channel model
             $data["channel_list"]=$this->channel_model->getChannelAll();
            //end get all channel model

             //get customer service
             // $data["customerService"]=$this->servicesuser_model->getCustServiceById($id);
             //create custom customer service
              $servicelist=$this->customer_model->getCustomerService($id);
              // $bookinglist=$this->booking_model->getBookingService($booking_id);
              $serviceData=array();
              foreach ($servicelist as $servicerow) {
                    $datarow=array();
                     $datarow['id']= $servicerow->id;
            $datarow['purchased_qty']= $servicerow->purchased_qty;
            $datarow['purchased_date']= $servicerow->purchased_date;
            // //calculate available qty
            //     $available_qty=$servicerow->available_qty;
            //     $usedQuantity=$this->servicesuser_model->getAvailableServiceUser($servicerow->id);    
            // //end calculate available qty

                //calculate available qty
                $available_qty=$servicerow->available_qty;
                $usedQuantity=$this->servicesuser_model->getAvailableServiceUser($servicerow->id);
                if($usedQuantity!=null){
                    $outAvailable_qty=$available_qty-$usedQuantity;
                }else{
                    $outAvailable_qty=$available_qty;
                }    
            // //end calculate available qty


            // $datarow['available_qty']= $servicerow->available_qty;
            $datarow['available_qty']= $servicerow->available_qty;
            $datarow['leaving_qty']= $outAvailable_qty;
            // $datarow['available_qty']= $usedQuantity;

            $datarow['time']= $servicerow->time;
            $datarow['code']= $servicerow->code;
            $datarow['category_id']= $servicerow->category_id;
            $datarow['serviceName']= $servicerow->name;
            $datarow['work']= $this->services_model->serviceConvert($servicerow->work);
            $datarow['price']= $servicerow->price;
            $datarow['time']= $servicerow->time;
            
            $datarow['remark']=$servicerow->remark;
            $datarow['no_credit_rebate']= $servicerow->no_credit_rebate;
            //for booking list row
            // $datarow['checkedoption']=0;
            // foreach ($bookinglist as $bookingerow) {
            //     if($bookingerow->service_user_id==$servicerow->id){
            //         $datarow['checkedoption']=1;
            //     }
            // }//foreach ($bookinglist as $bookingerow) {
            //end for booking list row
            // if($outAvailable_qty>0){

                //cancel if quantity larger than 0 to show
                //if booking has become negative, it will hide the item
                    
                array_push($serviceData,$datarow);
            // }   

        }//foreach ($servicelist as $servicerow) {


            $data["customerService"]=$serviceData;

             
            //end get customer service
            $data['selectedmenu']='brcustomeradmin'; 


            //get customer booking 

            $data['customer_booking']=$this->booking_model->getCustomerBookingById($id);
            //end get customer booking

            $data['therapistlist']=$this->employee_model->getTheraphistAll($this->session->userdata('currentshop'));    

            $data['customerpoint']=$this->customerpoint_model->getCustomerPoint($id);

            $data['customertotalpoint']=$this->customerpoint_model->getCustomerTotalPoint($id);


            //get customer point history
            $data['customerpoint_history']=$this->customerpoint_model->getCustomerPointHistoryById($id);
            //end get  customer point history


            //get customer used point history
            $data['customerusedpoint_history']=$this->customerusedpoint_model->getCustomerUsedPointHistoryById($id);

            //end get customer used point history




            $this->load->view('/admin/brcustomeraddview',$data);
        
        }
        public function detail(){
            $userid = $this->session->userdata('userid');
            // $user_data = $this->session->userdata('USER_ID');

            if(empty($userid)){
                // $this->load->view('test1');
                redirect('/at-cms/login', 'refresh');
            }
            $this->load->helper('url');
            $config["base_url"] =  base_url() ."adminmain/index";
        // $config["total_rows"] = $this->Countries->record_count();
        
        // $config["total_rows"] = $this->frontenduser_model->record_count();
        
        $config["uri_segment"] = 3;
        $config["per_page"] = 10;
        $config["page"] = 0;

        // $page = ($this->uri->segment(3))? $this->uri->segment(3) : 0;

        $this->load->helper('url');
        if(!empty($this->uri->segment(3))){
            $page = $this->uri->segment(3);  
        }
        else{
            $page = $config["page"];
        }
        // get 11
        if(!empty($this->uri->segment(4))){
            $perpage = $this->uri->segment(4);  
        }
        else{
            $perpage = $config["per_page"];
        }
        // $perpage = $this->uri->segment(4);

        // $choice = $config["total_rows"] / $perpage;
        // $config["num_links"] = round($choice);
        // $config["num_links"] = ceil($choice);
        
        //end for pagination

        // $this->load->view('welcome_message');
        $data = array(
                'title' => 'My Title',
                'heading' => 'My Heading',
                'message' => 'My Message'
            );        
        // $data['total_rows']=$config["total_rows"];
        $data['page']=$page;
        $data['perpage']=$perpage;
        // $data['num_links'] = $config["num_links"];
        // $data['record']=$this->frontenduser_model->getAdmindata($perpage, $page);
        $data['base_url'] =$config["base_url"];
        $data['fullName'] = $this->session->userdata('fullName'); 

         //employee group data
        // $data['employeegroup']=$this->employeegroup_model->getAllEmployeeGroup();

        $data['shop']=$this->shop_model->getShopAll();
        $data['services']=$this->services_model->getAllServices();
        // dump($data['services']);
        // $data['employeeincometype']=$this->employee_model->getEmployeeIncomeType();

        //set default current shop id,
        //it may be delete in later
        if(empty($this->session->userdata('currentshop'))){
            $this->session->set_userdata('currentshop', 1); 
        }
        //end 
        $data['pagemethod']='add';
        $data['currentshop']= $this->session->userdata('currentshop');
        $data['customercode']=$this->shop_model->getShopcode($this->session->userdata('currentshop'));
        $data['shopimprove']=$this->shop_model->getSkinImprove();

        $data['bodyimprovelist']=$this->customerbody_model->getAll();

        $data['faceimprovelist']=$this->customerface_model->getAll();

        $data['firstzone']=$this->livingarea_model->getFirstZone();

        //end 

        //get customer data
            $data['pagemethod']='details';
            $id = $this->uri->segment(4);
            $data['customerdetails']=$this->customer_model->getCustomer($id);
            $data['customerdetailslivingarea']=$this->customer_model->getCustomerLivingArea($id);
            $data['customerdetailsPromotionCode']=$this->customer_model->getCustomerPromotionCode($id);
            $data['customerdetailsSkinImprove']=$this->customer_model->getCustomerSkinImprove($id);


            $data['customerdetailsBodyImprove']=$this->customer_model->getCustomerBodyImprove($id);

            $data['customerdetailsFaceImprove']=$this->customer_model->getCustomerFaceImprove($id);


            $userid = $this->session->userdata('userid');
            

            //get customer name

            $createrrow=$this->employee_model->getUserDetail($data['customerdetails']->created_by);
            $data['creator']=$createrrow;
            

             $updaterrow=$this->employee_model->getUserDetail($data['customerdetails']->updated_by);
            $data['updater']=$updaterrow;
            // var_dump($data['creator']);
            //end get customer name

             //get all shop data
        $data["shop_list"] = $this->shop_model->getShopAll();
        //end get customer data
        
            //get all member level
            $data["memberlevel_list"]=$this->customerlevel_model->getLevelAll();
            //end get all member level
            
             //get all channel model
             $data["channel_list"]=$this->channel_model->getChannelAll();
            //end get all channel model

             //get customer service
             // $data["customerService"]=$this->servicesuser_model->getCustServiceById($id);
            

             //create custom customer service
              $servicelist=$this->customer_model->getCustomerService($id);
              // $bookinglist=$this->booking_model->getBookingService($booking_id);
              $serviceData=array();
              foreach ($servicelist as $servicerow) {
                    $datarow=array();
                     $datarow['id']= $servicerow->id;
            $datarow['purchased_qty']= $servicerow->purchased_qty;
            $datarow['purchased_date']= $servicerow->purchased_date;
            // //calculate available qty
            //     $available_qty=$servicerow->available_qty;
            //     $usedQuantity=$this->servicesuser_model->getAvailableServiceUser($servicerow->id);    
            // //end calculate available qty

                //calculate available qty
                $available_qty=$servicerow->available_qty;
                $usedQuantity=$this->servicesuser_model->getAvailableServiceUser($servicerow->id);
                if($usedQuantity!=null){
                    $outAvailable_qty=$available_qty-$usedQuantity;
                }else{
                    $outAvailable_qty=$available_qty;
                }    
            // //end calculate available qty


            // $datarow['available_qty']= $servicerow->available_qty;
            $datarow['available_qty']= $servicerow->available_qty;
            $datarow['leaving_qty']= $outAvailable_qty;
            // $datarow['available_qty']= $usedQuantity;

            $datarow['time']= $servicerow->time;
            $datarow['code']= $servicerow->code;
            $datarow['category_id']= $servicerow->category_id;
            $datarow['serviceName']= $servicerow->name;
            $datarow['work']= $this->services_model->serviceConvert($servicerow->work);
            $datarow['price']= $servicerow->price;
            $datarow['time']= $servicerow->time;
            
            $datarow['remark']=$servicerow->remark;
            $datarow['no_credit_rebate']= $servicerow->no_credit_rebate;
            //for booking list row
            // $datarow['checkedoption']=0;
            // foreach ($bookinglist as $bookingerow) {
            //     if($bookingerow->service_user_id==$servicerow->id){
            //         $datarow['checkedoption']=1;
            //     }
            // }//foreach ($bookinglist as $bookingerow) {
            //end for booking list row
            // if($outAvailable_qty>0){

                //cancel if quantity larger than 0 to show
                //if booking has become negative, it will hide the item
                    
                array_push($serviceData,$datarow);
            // }   

        }//foreach ($servicelist as $servicerow) {


            $data["customerService"]=$serviceData;


             //end create custom customer service 

            //end get customer service










            $data['selectedmenu']='brcustomeradmin'; 

             //get customer booking 

            $data['customer_booking']=$this->booking_model->getCustomerBookingById($id);
            //end get customer booking




            $data['therapistlist']=$this->employee_model->getTheraphistAll($this->session->userdata('currentshop'));

             $data['customerpoint']=$this->customerpoint_model->getCustomerPoint($id);
    
            $data['customertotalpoint']=$this->customerpoint_model->getCustomerTotalPoint($id);

            //get customer point history
            $data['customerpoint_history']=$this->customerpoint_model->getCustomerPointHistoryById($id);
            //end get  customer point history


            //get customer used point history
            $data['customerusedpoint_history']=$this->customerusedpoint_model->getCustomerUsedPointHistoryById($id);

            //end get customer used point history

            $this->load->view('/admin/brcustomeraddview',$data);
        }
        public function level(){
            $this->load->library('session');
            $searchlevel=$this->input->post('level');
             //clearing $searchingword
            $searchlevel=trim($searchlevel);
            //end clearing $searchingword

            $this->session->set_userdata('searchlevel', $searchlevel);    

            $this->index();   
        }
        public function tempmem(){
            $this->load->library('session');
            $searchMem=$this->input->post('isTemp');
             //clearing $searchingword
            $searchMem=trim($searchMem);
            //end clearing $searchingword

            $this->session->set_userdata('searchmem', $searchMem);    

            $this->index();   
        }
        public function channel(){
            
            $this->load->library('session');
            $channelSelectID=$this->input->post('channelSelectID');
             //clearing $searchingword
            $channelSelectID=trim($channelSelectID);
            //end clearing $searchingword

            $this->session->set_userdata('channelSelectID', $channelSelectID);    

            $this->index(); 
        }
        public function display(){
            $this->load->library('session');
            $this->session->set_userdata('searchlevel',"");    
            $this->session->set_userdata('channelSelectID', ""); 
            $this->session->set_userdata('searchmem', ""); 
            //clean file ordering
            // $this->session->set_userdata('fileordering',"");  

            $this->index();
        }
        public function custdatalist(){
     
        // POST data
        $postData = $this->input->post();

        $serachlevel= $this->session->userdata('searchlevel');   
        $channelSelectID= $this->session->userdata('channelSelectID'); 
         $searchmem= $this->session->userdata('searchmem');


        $response = $this->customer_model->getCustomerAllWithDatatable($this->session->userdata('currentshop'),$serachlevel,$channelSelectID,$searchmem,$postData);

            echo json_encode($response);
        }
        public function custdatalistwithSecondShop(){
     
        // POST data
        $postData = $this->input->post();

        $serachlevel= $this->session->userdata('searchlevel');   
        $channelSelectID= $this->session->userdata('channelSelectID'); 
         $searchmem= $this->session->userdata('searchmem');


        $response = $this->customer_model->getCustomerAllShopWithDatatableWithSecondShop($this->session->userdata('currentshop'),$this->employee_model->getSecondShopid($this->session->userdata('userid')),$serachlevel,$channelSelectID,$searchmem,$postData);



            echo json_encode($response);
        }
}