<?php

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

class Floor_controller extends CI_Controller {

    public function __construct() {
        parent::__construct();
        // Your own constructor code
        $this->load->model('scheduler_model');
        $this->load->model('business_model');
        $this->load->model('visits_model');
        $this->load->model('accounting_model');
        $this->load->model('customer_model');
        $this->load->model('invoice_model');
        $this->load->model('dispatch_model');      
        $this->load->model('floor_model');      
       
    }

    
    public function floor_management($date=null){
                
        if ($this->session->userdata('role') == '' || $this->session->userdata('role') == 'Sh-Users') {
            $this->load->view('login_view');
            
        } else {

            if ($this->session->userdata('role') != 'Floor Manager' && $this->session->userdata('role') != 'Admin' && $this->session->userdata('role') != 'Super User') {
                redirect(base_url('scheduler'));
            }
            
            $today = date('Y-m-d');

            if(null !== $date){
               $today=$date;
               $data['date']=$today;
            }
            
            $data['invoices']=$this->invoice_model->getdayinvoices($today, 'desc', $data['status'],null);
            
            $this->load->view('includes/header',$data);
            $this->load->view('floor/floor_visits');
            $this->load->view('includes/footer');
        }

    }
    
    
    public function floor_list($floorid=null){
                
        if ($this->session->userdata('role') == '' || $this->session->userdata('role') == 'Sh-Users') {
            $this->load->view('login_view');
            
        } else {            
            
            $data['nav'] = 'business_floors';
            $data['subnav'] = 'business_floors';
            
            
            if(null != $this->input->post('floor_id')){
                $floorid=$this->input->post('floor_id');
            }
            
            $data['floors']=$this->floor_model->get_all_floors($floorid);
            $data['staffs']=$this->floor_model->get_floor_staff();
            
//            print_r($data['staffs']);
//            exit();
            $this->load->view('includes/header',$data);
            $this->load->view('floor/floor_list');
            $this->load->view('includes/footer');
        }

    }
    
    public function get_a_floor($floorid=null){
        //echo $floorid ;
        if(null == $floorid){
            $floorid = $this->input->post('floor_id');
        }
       
        $data=$this->floor_model->get_all_floors($floorid);
        
        echo (json_encode($data));
        die;
    }
    
    public function update_floor(){
        
        
        $result=$this->floor_model->update_floor();
        
        echo 'success|'.$result;
        die;
        
    }
    
    public function add_floor(){
        
        $result=$this->floor_model->add_floor();
        
        echo 'success|'.$result;
        die;
        
    }
}