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

class Brinvoiceadmintest3 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('Brinvoicemodel', 'invoice_model');
           $this->load->model('Brshopmodel', 'shop_model');
           $this->load->model('Brcustomermodel', 'customer_model');
           $this->load->model('Bremployeemodel', 'employee_model');
           $this->load->model('Brinvoicemodel', 'invoice_model');
           $this->load->model('BrBookingModel', 'booking_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++;

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


        //added for bora sarah special id to see all shop invoice 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["invoice_list"] = $this->invoice_model->getInvoiceAllShopWithDetail($data['currentshop'],$this->employee_model->getSecondShopid($this->session->userdata('userid')));
        }//if($this->session->userdata('userid')!= '22' && 
        //end added for bora sarah special id to see all shop invoice


        //get all shop data
        if($this->session->userdata('userid')!= '22' && $this->session->userdata('username')!='sarah'){
       
            $data["invoice_list"] = $this->invoice_model->getInvoiceAllWithDetail($data['currentshop']);
        }//if($this->session->userdata('userid')!= '22' && $this->session->userdata('username')!='sarah'){

        //end get all shop data

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

        $this->load->view('/admin/brinvoiceview',$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($this->session->userdata('brbooking_add')==false){
                 redirect('/at-cms/brinvoiceadmin', 'refresh');
            }
            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';
              //get customer list 
               $data['customerlist']=$this->customer_model->getCustomerAllShop();
               $data['therapistlist']=$this->employee_model->getTheraphistAll($this->session->userdata('currentshop'));
               $data['consultantlist']=$this->employee_model->getConsultantAll($this->session->userdata('currentshop'));
              //end get customer list

            //get booking id

             $bookingid = $this->uri->segment(4);
            $data['userid']=""; 
             if(!empty($bookingid)){
                $data['bookingid']=$bookingid ;
                $bookingrow=$this->booking_model->getBookingByid($bookingid);
                $data['user_id']=$bookingrow->user_id;
             }  
            //end get booking id


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

            // $data="";
            $this->load->view('/admin/brinvoiceaddviewtest3',$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');

            //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']='edit';

            //get shop data
              $invoiceid = $this->uri->segment(4);
               // $data['shopdetails']=$this->shop_model->getShopbyid($id);
            //end get shop data


            //get customer list 
               $data['customerlist']=$this->customer_model->getCustomerAllShop();
               $data['therapistlist']=$this->employee_model->getTheraphistAll($this->session->userdata('currentshop'));
               $data['consultantlist']=$this->employee_model->getConsultantAll($this->session->userdata('currentshop'));
              //end get customer list

            //added invoice detail
            $data['invoiceDetail']=$this->invoice_model->getInvoiceWithDetail($invoiceid);

            $data['invoiceItemDetail']=$this->invoice_model->getInvoiceItemDetail($invoiceid);

            //for checking service in userservice
            $data['invoiceItemDetailInService']=$this->invoice_model->checkItemDetailInService($data['invoiceItemDetail']);
            // var_dump($data['invoiceItemDetailInService']);
            //end for checking service in userservice

            $data['invoicePayment']=$this->invoice_model->getInvoicePayment($invoiceid);

            //end added invoice detail


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

            // $data="";
            $this->load->view('/admin/brinvoiceaddviewtest3',$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');

            //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

              $data['pagemethod']='detail';

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

            //get shop data
              $id = $this->uri->segment(4);
               $data['shopdetails']=$this->shop_model->getShopbyid($id);
            //end get shop data

            $data['selectedmenu']='brinvoiceadmin';
            
            // $data="";
            $this->load->view('/admin/brshopaddview',$data);
        }
        public function dispay(){
            echo "1";
            $this->load->helper('url');
        $page = $this->uri->segment(3);  // get 11
        $perpage = $this->uri->segment(4);
        echo "page";
        echo $page;
        echo "perpage";
        echo $perpage;
        }
}