<?php  

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



class Brcustomerpointend extends CI_Controller{

    public function __construct(){
        parent::__construct();
        $this->load->model('Brcustomermodel', 'customer_model');
        $this->load->model('Brshopmodel', 'shop_model');
        $this->load->model('BrservicesuserModel', 'servicesuser_model');

        $this->load->model('Brcustomerpointmodel','customerpoint_model');
        $this->load->model('BrBookingModel','booking_model');
    }
    //added function
    public function add(){
            $id=$this->input->post('id');
            $purchased_date=$this->input->post('purchased_date');
            $point=$this->input->post('point');
            $purchased_price=$this->input->post('purchased_price');
            $remark2=$this->input->post('remark2');

           


            $data= array(
                'purchased_date'=>$purchased_date,
                'point'=>$point,
                // 'chi_name'=>$chi_name,
                // 'eng_firstname'=>$eng_firstname,
                // 'inputadminname'=>$inputadminname,
                // 'eng_lastname'=>$eng_lastname,
                'purchased_price'=>$purchased_price,
                'remark'=>$remark2,
                'user_id'=>$id,


            );

            // $code="";
            // if($this->frontenduser_model->admin_exists($inputadminname)==false){
            //     $code="FAILURE";
            //     $msg="已有管理員姓名".$inputadminname;
            // }
            // else
            // if($this->customer_model->customercode_exists(strtolower($code))==false){
            //     $entercode=$code;
            //     $code="FAILURE";
            //     $msg="已有客戶編號".$entercode;
            // }

            // $headcode=$this->shop_model->getShopcodeHead($first_registered_tenant_no);


            if(false){
                // $entercode=$code;
                // $code="FAILURE";
                // $msg="新增失敗。已有客戶電話號碼".$mobile;
            }
            else{
                  $result=$this->customerpoint_model->insertCustomerPoint($data);

                
                if($result==false){
                    $code="FAILURE";
                    $msg="記錄不能加入";     
                }
                else{
                    $code="SUCCESS";
                    $msg="記錄成功加入"; 
                    //for add user it will add a secret key to database
                    
                    //end 

                }
            }

             
            

             header('Content-Type: application/json');
            // $code="SUCCESS";
            // $code="FAILURE";
            // $msg="已有相關記錄";
            // $myArray = ['id'=>12, 'name'=>'Topi'];
            $myArray = ['recordstatus'=>$code, 'msg'=>$msg];
            echo json_encode($myArray);
            // echo "posted";
        
    }
    public function update(){
            $id=$this->input->post('id');
            $purchased_date=$this->input->post('purchased_date');
            $point=$this->input->post('point');
            $purchased_price=$this->input->post('purchased_price');
            $remark=$this->input->post('remark');
           

    
            // $need_purchase_service=$this->input->post('need_purchase_service');
            // $service_id=$this->input->post('service_id');
            // $purchased_date=$this->input->post('purchased_date');
            // $purchased_qty=$this->input->post('purchased_qty');
            // $available_qty=$this->input->post('available_qty');
            // $remark2=$this->input->post('remark2');


            $data= array(
                'id'=>$id,
                'purchased_date'=>$purchased_date,
                'point'=>$point,
                // 'chi_name'=>$chi_name,
                // 'eng_firstname'=>$eng_firstname,
                // 'inputadminname'=>$inputadminname,
                // 'eng_lastname'=>$eng_lastname,
                'purchased_price'=>$purchased_price,
                'remark'=>$remark,
                // 'purchased_price'=>$purchased_price,
                // 'remark'=>$remark2,
                // 'purchased_date'=>$purchased_date,
                // 'need_purchase_service'=>$need_purchase_service,
                // 'service_id'=>$service_id,
                // 'purchased_date'=>$purchased_date,
                // 'purchased_qty'=>$purchased_qty,
                // 'available_qty'=>$available_qty,
                // 'remark2'=>$remark2,
  
            );

            // $code="";
            // if($this->frontenduser_model->admin_exists($inputadminname)==false){
            //     $code="FAILURE";
            //     $msg="已有管理員姓名".$inputadminname;
            // }
            // else
            // if($this->customer_model->customercode_existsbyid($code,$id)==false){
            //     $entercode=$code;
            //     $code="FAILURE";
            //     $msg="已有客戶編號".$entercode;
            // }
            // $headcode=$this->shop_model->getShopcodeHead($first_registered_tenant_no);


            if(false){
                // $entercode=$code;
                // $code="FAILURE";
                // $msg="更改失敗。已有客戶電話號碼".$mobile;
            }
            else{
                $result=$this->customerpoint_model->updateCustomerPoint($data);
                if($result==false){
                    $code="FAILURE";
                    $msg="記錄不能更改";     
                }
                else{
                    $code="SUCCESS";
                    $msg="記錄成功更改"; 
                    //for add user it will add a secret key to database
                    
                    //end 

                }
            }

             
            

             header('Content-Type: application/json');
            // $code="SUCCESS";
            // $code="FAILURE";
            // $msg="已有相關記錄";
            // $myArray = ['id'=>12, 'name'=>'Topi'];
            $myArray = ['recordstatus'=>$code, 'msg'=>$msg];
            echo json_encode($myArray);
            // echo "posted";
    }
    public function delete(){
            $id=$this->input->post('id');
    
            // $need_purchase_service=$this->input->post('need_purchase_service');
            // $service_id=$this->input->post('service_id');
            // $purchased_date=$this->input->post('purchased_date');
            // $purchased_qty=$this->input->post('purchased_qty');
            // $available_qty=$this->input->post('available_qty');
            // $remark2=$this->input->post('remark2');


            $data= array(
                'id'=>$id,

            );

            // $code="";
            // if($this->frontenduser_model->admin_exists($inputadminname)==false){
            //     $code="FAILURE";
            //     $msg="已有管理員姓名".$inputadminname;
            // }
            // else
            // if($this->customer_model->customercode_existsbyid($code,$id)==false){
            //     $entercode=$code;
            //     $code="FAILURE";
            //     $msg="已有客戶編號".$entercode;
            // }
            // $headcode=$this->shop_model->getShopcodeHead($first_registered_tenant_no);


            if(false){
                // $entercode=$code;
                // $code="FAILURE";
                // $msg="更改失敗。已有客戶電話號碼".$mobile;
            }
            else{
                $result=$this->customerpoint_model->deleteCustomerPoint($data);
                if($result==false){
                    $code="FAILURE";
                    $msg="記錄不能删除";     
                }
                else{
                    $code="SUCCESS";
                    $msg="記錄成功删除"; 
                    //for add user it will add a secret key to database
                    
                    //end 

                }
            }

             
            

             header('Content-Type: application/json');
            // $code="SUCCESS";
            // $code="FAILURE";
            // $msg="已有相關記錄";
            // $myArray = ['id'=>12, 'name'=>'Topi'];
            $myArray = ['recordstatus'=>$code, 'msg'=>$msg];
            echo json_encode($myArray);
            // echo "posted";
    }
    public function getCustPoint(){
        $id=$this->input->post('cust_id');
        $data=$this->customerpoint_model->getCustomerPoint($id);
        header('Content-Type: application/json');
        echo json_encode($data);
    } 
    public function getCustomerTotalByBookingId(){
        $bookingid=$this->input->post('booking_id');
           $bookingDetail=$this->booking_model->getBookingByid($bookingid); 

              
        $data=$this->customerpoint_model->getCustomerPoint($bookingDetail->user_id);
        header('Content-Type: application/json');
        echo json_encode($data);    

    }


    //end added function



    public function get($id=Null){
        $partnerlist=$this->frontenduser_model->getBannerAll();
        echo  '1';
        print_r($partnerlist);
    }

    
    
    public function status(){
        $action=$this->input->post('action');
            $personid=$this->input->post('personid');
            if($action=="add"){


        //insert first level id
            $data= array(

            'id'=>$personid,
            'status'=>1
            // 'level1id'=>$level1id,
            // // 'inputadminname'=>$inputadminname,
            // 'level2id'=>$level2id,
            // 'level3id'=>$level3id,
            // 'level4id'=>$level4id
        );

            $result=$this->customer_model->updateStatus($data);
        }
            if($action=="remove"){    
             $data= array(

             'id'=>$personid,
            'status'=>0
        );

         $result=$this->customer_model->updateStatus($data);
        }//if($action=="remove"){

            if($result==false){
                $code="FAILURE";
                $msg="記錄不能更改";     
            }
            else{
                $code="SUCCESS";
                $msg="記錄成功更改";    
            }

            header('Content-Type: application/json');
            // $code="SUCCESS";
            // $code="FAILURE";
            // $msg="已有相關記錄";
            // $myArray = ['id'=>12, 'name'=>'Topi'];
            $myArray = ['recordstatus'=>$code, 'msg'=>$msg];
            echo json_encode($myArray);
            // echo "posted";

    }
    public function edit(){
       
        // $request= new Request();
        // $admin=$request->getBody();

        // 'inputadminname':$('#inputadminname').val(),
        //     'inputloginname':$('#inputloginname').val(),
        //     'inputPassword'
        // $name=$this->input->post('name');
        
        //add security trim input-todo
        //hash password for security
        $inputcompanynameedit=$this->input->post('inputcompanynameedit');
        $inputfullnameedit=$this->input->post('inputfullnameedit');
        $inputteledit=$this->input->post('inputteledit');
        // $inputadminname=$this->input->post('inputadminnameedit');
        $inputloginname=$this->input->post('inputloginnameedit');
        $inputPassword=$this->input->post('inputPasswordedit');
        $id=$this->input->post('inputadminid');

        $data= array(

            'inputcompanynameedit'=>$inputcompanynameedit,
            'inputfullnameedit'=>$inputfullnameedit,
            'inputteledit'=>$inputteledit,
            // 'inputadminname'=>$inputadminname,
            'inputloginname'=>$inputloginname,
            'inputPassword'=>$inputPassword,
            'id'=>$id
        );

        $code="";
        // if($this->frontenduser_model->admin_existsbyid($inputadminname,$id)==false){
        //     $code="FAILURE";
        //     $msg="已有管理員姓名".$inputadminname;
        // }
        // else
        if($this->frontenduser_model->login_existsbyid(strtolower($inputloginname),$id)==false){
            $code="FAILURE";
            $msg="已有登入名稱".$inputloginname;
        }
        else{
            $result=$this->frontenduser_model->updateAdmin($data);
            if($result==false){
                $code="FAILURE";
                $msg="記錄不能更改";     
            }
            else{
                $code="SUCCESS";
                $msg="記錄成功更改";    
            }

            
        }

         
        

         header('Content-Type: application/json');
        // $code="SUCCESS";
        // $code="FAILURE";
        // $msg="已有相關記錄";
        // $myArray = ['id'=>12, 'name'=>'Topi'];
        $myArray = ['recordstatus'=>$code, 'msg'=>$msg];
        echo json_encode($myArray);
        // echo "posted";
    
    }
    // public function delete(){
    //     $inputdeletecheckboxvalue=$this->input->post('inputdeletecheckboxvalue');
    //     $result=true;
    //     foreach ($inputdeletecheckboxvalue as $key => $values){
    //         if($this->frontenduser_model->deleteAdmin($values)==false){
    //             $result=false; 
    //         }
           
            
    //     }//foreach ($inputdeletecheckboxvalue as $key => $values){
    
    //     if($result==true){
    //         $code="SUCCESS";
    //         $msg="相關記錄成功删徐";
    //     }
    //     else{
    //         $code="FAILURE";
    //         $msg="相關記錄不能删徐";
    //     }
       
    //     // $msg=$inputdeletecheckboxvalue;
    //     header('Content-Type: application/json');
    //     $myArray = ['recordstatus'=>$code, 'msg'=>$msg];
    //     echo json_encode($myArray);
    // }
    public function getadmindata(){
        $id=$this->input->post('user_id');
        $data=$this->frontenduser_model->getAdmindateByid($id);
        header('Content-Type: application/json');
        echo json_encode($data);
    }

}//class Admins {
